package com.handinfo.android.core.object;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.CopyOnWriteArrayList;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Point;
import android.graphics.PointF;
import android.text.TextPaint;
import android.view.MotionEvent;
import android.widget.Toast;

import com.handinfo.android.DWGameActivity;
import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.graphics.ITrans;
import com.handinfo.android.core.media.DWAudio;
import com.handinfo.android.core.net.BaseConnection;
import com.handinfo.android.core.net.DWConnectionCreator;
import com.handinfo.android.core.net.GameProtocol;
import com.handinfo.android.core.resource.DWSerializable;
import com.handinfo.android.core.resource.DWSerializableFactory;
import com.handinfo.android.core.resource.ResHead;
import com.handinfo.android.core.resource.Resource;
import com.handinfo.android.core.resource.ResourceManager;
import com.handinfo.android.core.resource.ResourceVerifier;
import com.handinfo.android.game.Attribute;
import com.handinfo.android.game.Function;
import com.handinfo.android.game.GameActor;
import com.handinfo.android.game.GameActorConstants;
import com.handinfo.android.game.GameEffect;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.Loading;
import com.handinfo.android.game.Login;
import com.handinfo.android.game.Npc;
import com.handinfo.android.game.Role;
import com.handinfo.android.game.Task;
import com.handinfo.android.game.particle.Particle;
import com.handinfo.android.game.particle.ParticleConstants;
import com.handinfo.android.game.skill.RoleCombatSkill;
import com.handinfo.android.game.skill.SkillConstants;
import com.handinfo.android.game.skill.SkillResult;
import com.handinfo.android.ui.ChatItem;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.ui.window.UIBaitan;
import com.handinfo.android.ui.window.UIHook;
import com.handinfo.android.ui.window.UIMail;
import com.handinfo.android.ui.window.UIMap;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWDialogMenu;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.utils.BinHeapAStar;
//import com.handinfo.android.utils.ChannelOperation;
import com.handinfo.android.utils.DWChannel;
import com.handinfo.android.utils.Tools;

public class Scene extends DWSerializable
{
	public SceneHandler m_sceneHandler;

	public Bitmap m_img_thumbnail;
	public DWGraphics m_graphics_thumbnail;
	public static final int THUMBNAIL_ZOOM_RATIO = 4;

	public Scene()
	{
		m_sceneHandler = new SceneHandler(this);
	}

	public boolean m_isRepaintOnce = false; // 场景是否重绘一次
	public boolean m_isPainting = true; // 场景是否需要绘制
	public String m_id;
	public String m_name;
	public int m_sceneType; // 安全区，非安全区等
	public String[] m_texts; // 场景中的文字信息
	public Role m_controlledActor;

	public Background m_bg; // 场景的背景
	public int m_bgWidth = Integer.MAX_VALUE; // 背景宽度（像素）
	public int m_bgHeight = Integer.MAX_VALUE; // 背景高度（像素）

	// //////////////////////////////////////////////////////////////////////////
	// // 场景静态资源

	public static Actor s_targetFrame; // 当前目标的标记框
	public static final String URL_ANIM_TARGETFRAME = "/anim/jiaoxiaguanghuan.anim";
	public static Actor s_clickMove; // 点击地面移动 动画
	public static final String URL_ANIM_CLICKMOVE = "/anim/npc_djk.anim";
	public static final int[][] SIZE_IMG_DAMAGENUM = { { 13, 13 }, { 9, 9 },
			{ 13, 13 }, { 9, 9 }, { 31, 14 } };

	// // 场景静态资源
	// //////////////////////////////////////////////////////////////////////////

	// //////////////////////////////////////////////////////////////////////////
	// /// ActorClass
	public Actor[] m_actorClasses; // 场景中非角色的ActorClass集合
	public byte[] m_actorClassesType; // 场景中非角色的ActorClass的类型集合
	public ResHead[] m_actorClassesResHead;
	// /// ActorClass
	// //////////////////////////////////////////////////////////////////////////

	// //////////////////////////////////////////////////////////////////////////
	// /// Actor
	public int m_actorMovableLayer; // 当前活动元件层
	public byte[] m_actorLayers; // 元件层

	public ArrayList<Actor> m_staticActors = new ArrayList<Actor>(); // 静态Actor集合(场景文件数据)
	// public Vector<Actor> m_dynamicActors = new Vector<Actor>(100, 20);
	// //动态Actor集合（服务器数据）
	public ArrayList<Actor> m_activeList = new ArrayList<Actor>(); // 活跃Actor集合（包括场景数据中的Actor和服务器发送的Actor）
	public ArrayList<Actor> m_drawList = new ArrayList<Actor>(); // 绘制Actor集合（包括场景数据中的Actor和服务器发送的Actor）

	public Hashtable<Long, GameActor> m_dynamicActors = new Hashtable<Long, GameActor>();

	// ////////////////
	// //摄像机相关
	public int m_cameraX; // 摄像机X坐标
	public int m_cameraY; // 摄像机Y坐标
	public int m_cameraW; // 摄像机宽度
	public int m_cameraH; // 摄像机高度
	public int m_destCameraX; // 目的摄像机X坐标
	public int m_destCameraY; // 目的摄像机Y坐标
	public int m_cameraSpeed = 20; // 摄像机移动速度
	public int m_cameraLimitX = 0; // 摄像机限制区起始点X坐标
	public int m_cameraLimitW = Integer.MAX_VALUE; // 摄像机限制区结束点X坐标
	public int m_cameraLimitY = 0; // 摄像机限制区起始点Y坐标
	public int m_cameraLimitH = Integer.MAX_VALUE; // 摄像机限制区结束点Y坐标
	public boolean m_forceCamera = true; // 强制将当前摄像机坐标移动到目的摄像机
	public boolean mSmoothCamera = false; // 是否平滑移动摄像机，每帧移动距离不能超过范围

	public Actor m_focusActor; // 当前摄像机元件
	public Actor m_oldFocusActor; // 用来临时记录上一个摄像机元件

	// ////////////////////////////////////
	public String[] m_dname;
	public short[] m_dx;
	public short[] m_dy;
	public int[] m_distance;
	public byte[] m_isIn;

	// 测试添加 以后可删除
	// bejin
	public boolean m_interact_start = false;// 是否采集
	private int m_interact_time = 0;// 采集时间
	public int m_timer = 0;

	public void startNPCInteract(int time)
	{
		m_interact_start = true;
		m_interact_time = time;
	}

	public void endNPCInteract()
	{
		m_interact_time = 0;
		m_interact_start = false;
	}

	public static void initStaticResource()
	{
		ResHead head = null;
//		// 光效
//		GameEffect.initStaticResource();

		// npc
//		Npc.initStaticResource();

//		// 伤害数字
//		SkillResult.initStaticResource();

		// 标记框
		head = new ResHead(DWSerializableFactory.RESOURCE_TYPE_ANIM,
				URL_ANIM_TARGETFRAME, 1);
		Animation anim = (Animation) (ResourceManager.getInstance()
				.loadResource(DWGameManager.getInstance().m_resourceStatic,
						head));
		s_targetFrame = new Actor(anim);
		// 点击地面效果
		ResHead clickMovehead = new ResHead(
				DWSerializableFactory.RESOURCE_TYPE_ANIM, URL_ANIM_CLICKMOVE, 1);
		Animation clickMoveAnim = (Animation) (ResourceManager.getInstance()
				.loadResource(DWGameManager.getInstance().m_resourceStatic,
						clickMovehead));
		s_clickMove = new Actor(clickMoveAnim);
		ResHead upgradeResH = new ResHead(
				DWSerializableFactory.RESOURCE_TYPE_ANIM,
				"/anim/effect_tishidonghua.anim", 1);
		Animation upgradeAnim = (Animation) (ResourceManager.getInstance()
				.loadResource(DWGameManager.getInstance().m_resourceStatic,
						upgradeResH));
		m_upgradeAcotr = new Actor(upgradeAnim);
		m_upgradeAcotr.m_actionOver = true;
		// m_upgradeAcotr.m_posX = DWGameManager.getInstance().Screen_Width >>
		// 1;
		// m_upgradeAcotr.m_posY = DWGameManager.getInstance().Screen_Height >>
		// 1;
		// s_img_map_bg = Tools.createImage(URL_IMG_MAP_BG);
		// s_img_map_place = Tools.createImage(URL_IMG_MAP_PLACE);
		// s_img_map_coord = Tools.createImage(URL_IMG_MAP_COORD);
	}

	/**
	 * 绘制指定层的元件
	 *
	 * @param g
	 * @param layerIndex
	 */
	public void drawActor(DWGraphics g, int layerIndex)
	{
		Actor a;
		int i;
		for (i = 0; i < m_drawList.size(); i++) {
			a = (Actor) m_drawList.get(i);
			if (a != null && a.m_layer == layerIndex) {
				try {
					a.draw(g, m_cameraX, m_cameraY);
				}
				catch (Exception e) {
					Tools.debug(e);
				}
			}
		}
	}

	/**
	 * 绘制整个场景
	 *
	 * @param scaleX
	 * @param scaleY
	 */
	public void paintScene(float scaleX, float scaleY)
	{
		if (m_graphics_thumbnail == null)
			return;
		DWGraphics g = m_graphics_thumbnail;
		int startLayer = 0;
		int endLayer = 0;
		if (m_actorLayers.length == 0) {
			if (m_bg != null) {
				m_bg.draw(g, 0, m_bg.m_layerCount - 1, scaleX, scaleY);
			}
			drawActor(g, 0, scaleX, scaleY);
		}
		else {
			for (int i = 0; i < m_actorLayers.length; i++) {
				endLayer = m_actorLayers[i];
				if (m_bg != null && endLayer >= startLayer) {
					m_bg.draw(g, startLayer, endLayer, scaleX, scaleY);
				}
				drawActor(g, i, scaleX, scaleY);
				startLayer = endLayer + 1;
			}
		}
	}

	public void drawActor(DWGraphics g, int layerIndex, float scaleX,
			float scaleY)
	{
		Actor a;
		int i;
		for (i = 0; i < m_staticActors.size(); i++) {
			a = (Actor) m_staticActors.get(i);
			if (a != null && a instanceof Actor && a.m_layer == layerIndex) {
				a.draw(g, 0, 0, scaleX, scaleY);
			}
		}
	}

	public void drawSpecialEffect(DWGraphics g)
	{
		g.setClip(0, 0, DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		g.setColor(0x88000000);
		g.fillRect(0, 0, DWGameManager.Screen_Width,
				DWGameManager.Screen_Height);

	}

	/**
	 * 根据id获得role
	 *
	 * @param id
	 * @return
	 */
	public Role getRoleByID(long id)
	{
		GameActor actor = m_dynamicActors.get(id);
		if (actor != null && actor instanceof Role)
			return (Role) actor;
		return null;
	}

	/**
	 * 移除指定id的role
	 *
	 * @param id
	 */
	public GameActor removeGameActorByID(long id)
	{
		return m_dynamicActors.remove(id);
	}

	/**
	 * 更新m_activeList和m_drawList
	 */
	public void updateActorList()
	{
		// 得到处于活动范围内的元件集合，绘制集合将在此集合中产生
		m_activeList.clear();
		Actor a;

		if (m_staticActors != null) {
			for (Actor actor : m_staticActors) {
				if (actor == null)
					continue;
				if (actor.m_needDraw && actor.m_enabled)
					m_activeList.add(actor);
			}
		}
		if (m_dynamicActors != null) {
			Object[] objs = m_dynamicActors.values().toArray();
			for (int i = 0; i < objs.length; i++) {
				Actor actor = (Actor) objs[i];
				if (actor == null)
					continue;
				if (actor instanceof Role) {
					Role r = (Role) actor;
					if (r.m_pet != null) {
						if (!DWGameManager
								.getSetting_graphics(DWGameManager.设置画面_显示友方玩家)) {
							if (r.checkTargetFriend(m_controlledActor)
									&& r != m_controlledActor) {
								continue;
							}
						}
						if (!DWGameManager
								.getSetting_graphics(DWGameManager.设置画面_显示敌方玩家)) {
							if (!r.checkTargetFriend(m_controlledActor)
									&& r != m_controlledActor) {
								continue;
							}
						}
						if (actor.m_needDraw && actor.m_enabled) {
							m_activeList.add(r.m_pet);
						}
					}
				}
				if (actor.m_needDraw && actor.m_enabled)
					m_activeList.add(actor);
			}
		}
		if (s_clickMove != null && s_clickMove.m_enabled == true) {
			m_activeList.add(s_clickMove);
		}
		if (m_effects != null) {
			Object[] objs = m_effects.toArray();
			for (int i = 0; i < objs.length; i++) {
				Actor actor = (Actor) objs[i];
				if (actor == null)
					continue;
				if (actor.m_needDraw && actor.m_enabled)
					m_activeList.add(actor);
			}
		}
		// 得到需要绘制在屏幕上的元件集合
		m_drawList.clear();
		int insertPos;
		for (int i = 0; i < m_activeList.size(); i++) {
			a = (Actor) m_activeList.get(i);
			// 元件不显示则跳过
			if (!a.m_needDraw || !a.m_visible) {
				continue;
			}
			insertPos = 0;
			while (insertPos < m_drawList.size()
					&& ((Actor) m_drawList.get(insertPos)).m_posY < a.m_posY) {
				insertPos++;
			}
			m_drawList.add(insertPos, a);
		}
	}

	/**
	 * 逻辑
	 */
	public void updateLogic()
	{
		keyLogic();
		for (Actor actor : m_staticActors) {
			if (actor != null && actor.m_enabled) {
				actor.updatePos();
				actor.logic();
				actor.nextFrame();
			}
		}

		Object[] objs = m_dynamicActors.values().toArray();

		for (int i = 0; i < objs.length; i++) {
			Actor actor = (Actor) objs[i];
			if (actor != null && actor.m_enabled) {
				try {
					actor.updatePos();
					actor.logic();
				}
				catch (Exception e) {
					e.printStackTrace();
				}
				actor.nextFrame();
			}
		}

		if (s_clickMove != null && s_clickMove.m_enabled) {
			s_clickMove.updatePos();
			s_clickMove.logic();
			s_clickMove.nextFrame();
		}

		Object[] effects = m_effects.toArray();
		for (int i = 0; i < effects.length; i++) {
			Actor actor = (Actor) effects[i];
			if (actor != null && actor.m_enabled) {
				actor.updatePos();
				actor.logic();
				actor.nextFrame();
			}
		}
	}

	/**
	 * 场景帧处理，用于一些动作执行中使用，仅进行场景中元件和背景帧的处理而不进行逻辑处理
	 */
	public void updateFrame()
	{
		// 如果背景不为空则执行背景逻辑
		if (m_bg != null) {
			m_bg.tick();
		}
		// 遍历场景中所有的元件，执行元件逻辑
		Actor a;
		// 更新静态Actors位置
		for (int i = m_staticActors.size() - 1; i >= 0; i--) {
			a = (Actor) m_staticActors.get(i);
			if (a != null && a.m_enabled) {
				a.updatePos();
			}
		}
	}

	// TODO
	public Hashtable<Integer, Vector<Particle>> m_particle;
	public Vector<Vector<Particle>> m_particleList;

	/** 创建一组粒子 */
	public void startParticle(int type, int Trajectory)
	{
		if (m_particle == null) {
			m_particle = new Hashtable<Integer, Vector<Particle>>();
		}
		Vector<Particle> vc = new Vector<Particle>();
		Particle par = null;
		switch (type) {
			case ParticleConstants.动画组_结婚:
				par = new Particle(ParticleConstants.类型_喜灯,
						ParticleConstants.轨迹_喜灯左);
				vc.add(par);
				par = new Particle(ParticleConstants.类型_喜灯,
						ParticleConstants.轨迹_喜灯右);
				vc.add(par);
				par = new Particle(ParticleConstants.类型_亲亲,
						ParticleConstants.轨迹_亲亲静止);
				vc.add(par);
				for (int i = 0; i < 10; i++) {
					par = new Particle(ParticleConstants.类型_闪心,
							ParticleConstants.轨迹_闪心);
					vc.add(par);
				}
				break;
			case ParticleConstants.动画组_元宝雨_右:
				int num = 20;
				for (int i = 0; i < num; i++) {
					par = new Particle(ParticleConstants.类型_元宝, Trajectory);
					vc.add(par);
				}
				break;
			case ParticleConstants.动画组_定点礼花0:
				num = Tools.random(3, 6);
				for (int i = 0; i < num; i++) {
					par = new Particle(ParticleConstants.类型_礼花0,
							ParticleConstants.轨迹_定点礼花0);
					vc.add(par);
				}
				break;
			default:
				num = 20;
				for (int i = 0; i < num; i++) {
					par = new Particle(type, Trajectory);
					vc.add(par);
				}
				break;
		}
		m_particle.put(type, vc);
		vc = null;
	}

	/** 道具使用粒子效果 */
	public void startParticleForList(int type, int Trajectory)
	{
		if (m_particleList == null) {
			m_particleList = new Vector<Vector<Particle>>();
		}
		Vector<Particle> vc = new Vector<Particle>();
		Particle par = null;
		switch (type) {
			case ParticleConstants.动画组_结婚:
				par = new Particle(ParticleConstants.类型_喜灯,
						ParticleConstants.轨迹_喜灯左);
				vc.add(par);
				par = new Particle(ParticleConstants.类型_喜灯,
						ParticleConstants.轨迹_喜灯右);
				vc.add(par);
				par = new Particle(ParticleConstants.类型_亲亲,
						ParticleConstants.轨迹_亲亲静止);
				vc.add(par);
				for (int i = 0; i < 10; i++) {
					par = new Particle(ParticleConstants.类型_闪心,
							ParticleConstants.轨迹_闪心);
					vc.add(par);
				}
				break;
			case ParticleConstants.动画组_元宝雨_右:
				int num = 20;
				for (int i = 0; i < num; i++) {
					par = new Particle(ParticleConstants.类型_元宝, Trajectory);
					vc.add(par);
				}
				break;
			case ParticleConstants.动画组_定点礼花0:
				num = Tools.random(15, 20);
				for (int i = 0; i < num; i++) {
					par = new Particle(ParticleConstants.类型_礼花0,
							ParticleConstants.轨迹_定点礼花0);
					vc.add(par);
				}
				break;
			default:
				num = 20;
				for (int i = 0; i < num; i++) {
					par = new Particle(type, Trajectory);
					vc.add(par);
				}
				break;
		}
		m_particleList.add(vc);
		vc = null;
	}

	/** 删除一组粒子 */
	public void closeParticle(int index)
	{
		if (m_particle != null && !m_particle.isEmpty()) {
			Integer in = Integer.valueOf(index);
			Tools.debugPrintln("closeParticle in=" + in.intValue());
			if (m_particle.containsKey(in)) {
				Tools.debugPrintln("closeParticle contains in=");
				m_particle.remove(in);
			}
		}
	}

	/** 绘制粒子集合 */
	public void drawParticle(DWGraphics g)
	{
		if (m_particle != null && !m_particle.isEmpty()) {
			for (Iterator<Integer> it = m_particle.keySet().iterator(); it
					.hasNext();) {
				Integer key = it.next();
				Vector<Particle> list = m_particle.get(key);
				for (Particle obj : list) {
					obj.paint(g);
				}
			}

		}
	}

	/** 绘制粒子集合 */
	public void drawParticleList(DWGraphics g)
	{
		if (m_particleList != null && m_particleList.size() > 0) {
			Vector<Particle> list = m_particleList.elementAt(0);
			if (list != null) {
				for (Particle obj : list) {
					obj.paint(g);
				}
			}
		}
	}

	/** 粒子集合的运行逻辑 */
	public void updataParticle()
	{
		if (m_particle != null && !m_particle.isEmpty()) {
			for (Iterator<Integer> it = m_particle.keySet().iterator(); it
					.hasNext();) {
				Integer key = it.next();
				Vector<Particle> list = m_particle.get(key);
				for (Particle obj : list) {
					obj.logic();
				}
			}

		}
	}

	/** 粒子集合的运行逻辑 */
	public void updataParticleList()
	{
		if (m_particleList != null && m_particleList.size() > 0) {
			Vector<Particle> list = m_particleList.elementAt(0);
			boolean flag = true;
			if (list != null) {
				for (Particle obj : list) {
					obj.logic();
					if (!obj.isLife) {
						flag = false;
					}
				}
				if (flag) {
					m_particleList.remove(list);
				}
			}
		}
	}

	public void keyLogic()
	{
		if (m_interact_start) {
			if (--m_interact_time < 0) {
				Tools.debugPrintln("NPC交互读条结束！");
				endNPCInteract();
				DWGameManager.getInstance().m_role.stopCasting();
				DWGameManager.getInstance().m_role.stopCastingDescription();
				DWGameManager.getInstance().getSendMessage()
						.sendNPCInteractEnd(m_read_spell_type);
				m_controlledActor
						.stay(DWGameManager.getInstance().m_role.m_direct);
				goOnIteract();
			}
		}
	}

	// //////////////////////////////////////////////////////////////////////////
	// //// 摄像机相关

	/**
	 * 设置摄像机元件
	 *
	 * @param viewActor
	 */
	public void setFocusActor(Actor viewActor)
	{
		this.m_oldFocusActor = this.m_focusActor;
		this.m_focusActor = viewActor;
	}

	/**
	 * 更新摄像机信息
	 */
	public void updateCamera()
	{
		if (m_focusActor != null) {
			m_destCameraX = m_focusActor.m_posX - (m_cameraW >> 1);
			m_destCameraY = m_focusActor.m_posY - (m_cameraH >> 1);
		}
		// 调整摄像机
		if (m_cameraX < m_destCameraX) {
			m_cameraX += m_cameraSpeed;
			if (m_cameraX > m_destCameraX) {
				m_cameraX = m_destCameraX;
			}
		}
		if (m_cameraX > m_destCameraX) {
			m_cameraX -= m_cameraSpeed;
			if (m_cameraX < m_destCameraX) {
				m_cameraX = m_destCameraX;
			}
		}
		if (m_cameraY < m_destCameraY) {
			m_cameraY += m_cameraSpeed;
			if (m_cameraY > m_destCameraY) {
				m_cameraY = m_destCameraY;
			}
		}
		if (m_cameraY > m_destCameraY) {
			m_cameraY -= (m_cameraSpeed);
			if (m_cameraY < m_destCameraY) {
				m_cameraY = m_destCameraY;
			}
		}
		if (m_forceCamera || !mSmoothCamera) { // 是否强制切换摄像机
			m_cameraX = m_destCameraX;
			m_cameraY = m_destCameraY;
			m_forceCamera = false;
		}
		setCameraXY(m_cameraX, m_cameraY);
	}

	/**
	 * 设置摄像机限制区域
	 *
	 * @param cameraX
	 * int
	 * @param cameraY
	 * int
	 * @param cameraW
	 * int
	 * @param cameraH
	 * int
	 */
	public void setCameraLimit(int cameraX, int cameraY, int cameraW,
			int cameraH)
	{
		m_cameraLimitX = cameraX;
		m_cameraLimitY = cameraY;
		m_cameraLimitW = cameraW;
		m_cameraLimitH = cameraH;
	}

	/**
	 * 设置场景摄像机
	 *
	 * @param viewX
	 * @param viewY
	 */
	public void setCameraXY(int cameraX, int cameraY)
	{
		// 有特殊的摄像机限制
		// this.m_cameraX = Tools.limit(cameraX, mCameraLimitX,
		// mCameraLimitX + mCameraLimitW - AbstractGameScreen.SCREEN_WIDTH);
		// this.m_cameraY = Tools.limit(cameraY, mCameraLimitY,
		// mCameraLimitY + mCameraLimitH - AbstractGameScreen.SCREEN_HEIGHT);

		this.m_cameraX = Tools.limit(cameraX, 0, m_bgWidth
				- DWGameManager.Screen_Width);
		this.m_cameraY = Tools.limit(cameraY, 0, m_bgHeight
				- DWGameManager.Screen_Height);
		this.m_cameraX = Math.max(0, this.m_cameraX);
		this.m_cameraY = Math.max(0, this.m_cameraY);
		if (m_bg != null) {
			m_bg.setCameraXY(this.m_cameraX, this.m_cameraY);
		}
	}

	public void setCameraWH(int cameraW, int cameraH)
	{
		m_cameraW = cameraW;
		m_cameraH = cameraH;
	}

	// //// 摄像机相关
	// //////////////////////////////////////////////////////////////////////////

	public void addDynamicActor(GameActor actor)
	{
		if (actor.m_anims != null && actor.m_anims.length > 0) {
			if (actor instanceof Role) {
				actor.m_anim = actor.m_anims[Role.ANIM_HEAD];
			}
			else {
				actor.m_anim = actor.m_anims[0];
			}
		}
		actor.activate();
		actor.m_scene = this;
		actor.m_layer = this.m_actorMovableLayer;
		if (actor instanceof Npc) {
			Npc npc = (Npc) actor;
			if (npc.m_type == GameActorConstants.ACTOR_TYPE_GATE) {
				actor.m_layer -= 1;
				if (actor.m_layer < 0) {
					actor.m_layer = 0;
				}
			}
		}
		actor.m_resource = DWGameManager.getInstance().m_resourceDynamic;
		m_dynamicActors.put(actor.m_gameId, actor);
	}

	public void addDynamicActors(Map<Long, GameActor> actors)
	{
		for (GameActor actor : actors.values()) {
			try {
				if (actor.m_anims != null && actor.m_anims.length > 0) {
					if (actor instanceof Role) {
						actor.m_anim = actor.m_anims[Role.ANIM_HEAD];
					}
					else {
						actor.m_anim = actor.m_anims[0];
					}
				}
				actor.activate();
				actor.m_scene = this;
				actor.m_layer = this.m_actorMovableLayer;
				if (actor.m_type == GameActorConstants.ACTOR_TYPE_GATE) {
					actor.m_layer -= 1;
					if (actor.m_layer < 0) {
						actor.m_layer = 0;
					}
				}
				actor.m_resource = DWGameManager.getInstance().m_resourceDynamic;
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}

		m_dynamicActors.putAll(actors);
	}

	/**
	 * 如果m_dynamicActors中的actor不在actors中，则将该actor置成deactivate
	 *
	 * @param actors
	 */
	public void deactiveDynamicActors(Map<Long, GameActor> actors)
	{
		for (GameActor actor : m_dynamicActors.values()) {
			if (!actors.containsKey(actor.m_gameId)) {
				// actor已死，无需再处理
				if (!actor.isDead()) {
					actor.deactivate();
				}
			}
		}
	}

	protected static final int[] trans = { ITrans.TRANS_NONE,
			ITrans.TRANS_ROT90, ITrans.TRANS_ROT180, ITrans.TRANS_ROT270,
			ITrans.TRANS_MIRROR, ITrans.TRANS_MIRROR_ROT90,
			ITrans.TRANS_MIRROR_ROT180, ITrans.TRANS_MIRROR_ROT270 };
	protected static final int[] anchor = { ITrans.LEFT | ITrans.TOP,
			ITrans.LEFT | ITrans.BOTTOM, ITrans.HCENTER | ITrans.TOP,
			ITrans.HCENTER | ITrans.BOTTOM, ITrans.RIGHT | ITrans.TOP,
			ITrans.RIGHT | ITrans.BOTTOM };

	public void loadActorClasses(Resource res) throws IOException
	{
		m_actorClasses = new Actor[m_refsResHead.length - 1];
		m_actorClassesType = new byte[m_refsResHead.length - 1];
		m_actorClassesResHead = new ResHead[m_refsResHead.length - 1];
		for (int i = 0; i < m_actorClasses.length; i++) {
			m_actorClasses[i] = (Actor) (ResourceManager.getInstance()
					.loadResource(res, m_refsResHead[i + 1]));
			m_actorClasses[i].m_scene = this;
			m_actorClasses[i].m_visible = false;
			m_actorClasses[i].m_enabled = false;
			m_actorClassesType[i] = m_refsResHead[i + 1].m_type;
			m_actorClassesResHead[i] = m_refsResHead[i + 1];
		}
	}

	public void loadBackground(Resource res) throws IOException
	{
		m_bg = (Background) (ResourceManager.getInstance().loadResource(res,
				m_refsResHead[0]));
	}

	public void loadActorClasses(Resource res, DataInputStream dis)
			throws IOException
	{
		int size = dis.readShort();
		m_actorClasses = new Actor[size];
		m_actorClassesResHead = new ResHead[size];
		for (int i = 0; i < m_actorClasses.length; i++) {
			m_actorClassesResHead[i] = new ResHead(dis.readByte(),
					DWSerializableFactory.DIR_AC.concat(dis.readUTF()).concat(
							DWSerializableFactory.EXTENSION_AC), 1);
			switch (m_actorClassesResHead[i].m_type) {
				case DWSerializableFactory.RESOURCE_TYPE_ACTOR:
					m_actorClasses[i] = new Actor(this);
					break;
				case DWSerializableFactory.RESOURCE_TYPE_NPC:
					m_actorClasses[i] = new Npc();
					break;
				default:
					break;
			}
			if (m_actorClasses[i] != null) {
				m_actorClasses[i].read(res, dis);
				res.put(m_actorClassesResHead[i], m_actorClasses[i]);
			}
		}
	}

	@Override
	public void read(Resource res, DataInputStream dis) throws IOException
	{
		readHead(res, dis);
		loadActorClasses(res, dis);
		loadBackground(res);
		// 载入名字
		m_name = dis.readUTF();
		Tools.debugPrintln("ags read name : " + m_name);
		// 活动层
		m_actorMovableLayer = dis.readByte();
		// 载入元件层数据
		int count = dis.readByte(); // 元件层数量
		m_actorLayers = new byte[count];
		for (int i = 0; i < count; i++) {
			m_actorLayers[i] = dis.readByte();
		}
		// 载入场景中字符串
		count = dis.readShort();
		m_texts = new String[count];
		for (int i = 0; i < count; i++) {
			m_texts[i] = dis.readUTF();
		}
		// 载入Actor信息
		count = dis.readShort();
		Actor actorClass;
		for (int i = 0; i < count; i++) {
			int inx = dis.readShort();
			actorClass = m_actorClasses[inx];
			Actor actorInstance = null;
			if (actorClass != null) {
				switch (m_actorClassesResHead[inx].m_type) {
					case DWSerializableFactory.RESOURCE_TYPE_ACTOR:
						actorInstance = actorClass.clone();
						break;
					default:
						// 空出该索引位，因为脚本动画是以索引为依据取Actor
						dis.skip(10);
						m_staticActors.add(null);
						continue;
				}
			}
			else {
				switch (m_actorClassesResHead[inx].m_type) {
					case DWSerializableFactory.RESOURCE_TYPE_ACTOR:
						actorInstance = new Actor();
						break;
					default:
						// 空出该索引位，因为脚本动画是以索引为依据取Actor
						dis.skip(10);
						m_staticActors.add(null);
						continue;
				}
			}
			m_staticActors.add(actorInstance);
			actorInstance.m_resHead = m_actorClassesResHead[inx];
			actorInstance.m_flag = dis.readInt();
			actorInstance.m_flipX = (actorInstance.m_flag & 0x01) != 0;
			actorInstance.m_flipY = (actorInstance.m_flag & 0x02) != 0;
			actorInstance.m_enabled = true;
			actorInstance.m_visible = true;
			int action = dis.readByte();
			if (action < 0) {
				action += 256;
			}
			actorInstance.setAction(action, true, true);
			actorInstance.m_layer = dis.readByte();
			actorInstance.m_posX = dis.readShort();
			actorInstance.m_posY = dis.readShort();
			actorInstance.m_id = (short) i;
		}
		// 载入场景中事件和脚本相关数据
		// m_script.loadTrailerData(dis);

		checkLoadFinished();
	}

	@Override
	public synchronized void updateComponent(ResHead head,
			DWSerializable component)
	{
		if (m_loadFinished)
			return;
		if (head.m_type != DWSerializableFactory.RESOURCE_TYPE_BG
				&& head.m_type != DWSerializableFactory.RESOURCE_TYPE_ACTOR)
			return;
		if (m_refsResHead == null || m_refsResHead.length == 0)
			return;
		for (int i = 0; i < m_refsResHead.length; i++) {
			if (m_refsResHead[i].equals(head)) {
				if (i == 0) {
					m_bg = (Background) component;
				}
				checkLoadFinished();
			}
		}
	}

	@Override
	public void checkLoadFinished()
	{
		if (m_bg == null) {
			m_loadFinished = false;
			return;
		}
		if (m_actorClasses == null) {
			m_loadFinished = false;
			return;
		}
		for (int i = 0; i < m_actorClasses.length; i++) {
			if (m_actorClasses[i] == null) {
				m_loadFinished = false;
				return;
			}
		}
		m_loadFinished = true;
	}

	@Override
	public boolean isContainRefHead(ResHead head)
	{
		if (head.m_type != DWSerializableFactory.RESOURCE_TYPE_BG
				&& head.m_type != DWSerializableFactory.RESOURCE_TYPE_ACTOR)
			return false;
		return super.isContainRefHead(head);
	}

	@Override
	public void dispose()
	{
		disposeHead();
		DWControlsManager.getInstance().removeAllControl();
		if (m_actorClasses != null) {
			for (int i = 0; i < m_actorClasses.length; i++) {
				if (m_actorClasses[i] != null) {
					m_actorClasses[i] = null;
				}
			}
			m_actorClasses = null;
		}
		m_actorClassesType = null;
		m_actorLayers = null;
		m_bg = null;
		if (m_dynamicActors != null) {
			for (Actor actor : m_dynamicActors.values()) {
				if (actor != null) {
					actor = null;
				}
			}
			m_dynamicActors.clear();
			m_dynamicActors = null;
		}
		if (m_staticActors != null) {
			for (Actor actor : m_staticActors) {
				if (actor != null) {
					actor = null;
				}
			}
			m_staticActors.clear();
			m_staticActors = null;
		}
		m_focusActor = null;

		m_graphics_thumbnail = null;

		if (m_img_thumbnail != null) {
			m_img_thumbnail.recycle();
			m_img_thumbnail = null;
		}
	}

	/**
	 * 切换场景确认信息
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvSceneConfirmation(DataInputStream dis) throws IOException
	{
		short con = dis.readShort();
		if (con == 1) {
			setTargetActor(null);
			if (!DWGameManager.getInstance().m_role.m_is_autopath) {
				DWGameManager.getInstance().m_role.keyAnyStopOther();
			}
			DWGameManager.getInstance().m_role.m_is_autopath = false;
			Loading.s_progress = Loading.SCENE_PROCESS;
			Loading loading = new Loading();
			DWGameManager.getInstance().setGameHandler(loading);
			DWGameManager.getInstance().setGameState(DWGameManager.GS_LOADING);
			Tools.debugPrintln("确认切换场景!");
		}
		else {
			Tools.debugPrintln("切换场景确认信息失败!");
		}
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);

	}

	/**
	 * 使用粒子效果
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvUseParticle(DataInputStream dis) throws IOException
	{
		long guid = dis.readLong();// 角色ID
		byte type = dis.readByte();// 粒子动画组类型
		startParticleForList(type, 0);
	}

	/**
	 * 更新角色属性
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvUpdateRoleProperties(DataInputStream dis)
			throws IOException
	{
		Role role = DWGameManager.getInstance().m_role;

		// 属性
		int size = dis.readByte();
//		Tools.debugPrintln("更新角色属性"+size);
		if (role.m_attributes == null) {
			role.m_attributes = new int[size];
		}
		for (int i = 0; i < size; i++) {
			role.m_attributes[i] = dis.readInt();
		}

		role.m_zhanli = dis.readLong();
		Tools.debugPrintln("战力指数: " + role.m_zhanli);

		if (m_zhanli_state == true) {
			UIWindows.getInstance().m_zhanli.open_other(role.m_zhanli);//战力相关
			m_zhanli_state = false;
		}

		role.m_hpMax = role.getAttr(Attribute.MAX_HP);
		Tools.debugPrintln("当前HP_MAX: " + role.m_hp);

		role.m_mpMax = role.getAttr(Attribute.MAX_MP);
		Tools.debugPrintln("当前MP_MAX: " + role.m_mp);

		Tools.debugPrintln("进入指令701");
		Tools.debugPrintln("当前命中: " + role.m_attributes[Attribute.HIT]);

		if (UIWindows.getMain() != null) {
			UIWindows.getMain().updateMyHead();
		}
	}

	/**
	 * 增删玩家金钱
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvRoleMoney(DataInputStream dis) throws IOException
	{
		byte type = dis.readByte();
		long count = dis.readLong();
		Tools.debugPrintln("读取玩家货币增删 type : " + type + ",count : " + count);
		// 0- 金钱
		// 1- 银票
		// 2- 元宝
		switch (type) {
			case Role.CURRENCY_TYPE_GOLD:
				long gold = count - DWGameManager.getInstance().m_role.m_gold;
				if (gold > 0) {
					ChatItem item = ChatItem.createChatItem(ChatItem.TYPE_FALL,
							ChatItem.ID_NONE, "", "", "您获得" + gold + "金", (byte) 0,
							(byte) 0);
					DWGameManager.getInstance().m_role.addToChat(item);
				}
				DWGameManager.getInstance().m_role.m_gold = count;
				UIWindows.getInstance().m_bag.setMoney();
				break;
			case Role.CURRENCY_TYPE_ZHANGONG:
				long valuezg = count
						- DWGameManager.getInstance().m_role.m_zhangong;
				DWGameManager.getInstance().m_role.m_zhangong = count;
				if (valuezg > 0) {
					SkillResult sr = new SkillResult(
							GameActorConstants.ACTOR_TYPE_ROLE,
							m_controlledActor.m_gameId, (int) valuezg);
					sr.show(this, m_controlledActor.m_posX + Tools.random(20),
							m_controlledActor.m_posY - Tools.random(50),
							SkillResult.战功);
				}
				break;
			case Role.CURRENCY_TYPE_RMB:
				DWGameManager.getInstance().m_role.m_rmb = count;
				if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_shop.m_sp_frame) == true) {
					UIWindows.getInstance().m_shop.m_sp_yuanbao.setText("当前元宝："
							+ DWGameManager.getInstance().m_role.m_rmb);
				}
				if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_recharge.m_recharge_Frame) == true) {
					UIWindows.getInstance().m_recharge.m_recharge_tb[UIWindows.getInstance().m_recharge.yuanbaoshuliang]
							.setText(String.valueOf(DWGameManager.getInstance().m_role.m_rmb));
				}
				break;
			case Role.CURRENCY_TYPE_BANGGONG:
				DWGameManager.getInstance().m_role.m_banggong = count;
				break;
			case Role.CURRENCY_TYPE_XIUWEI:
				long valuexw = count - DWGameManager.getInstance().m_role.m_xiuwei;
				DWGameManager.getInstance().m_role.m_xiuwei = count;
				if (valuexw > 0) {
					SkillResult sr = new SkillResult(
							GameActorConstants.ACTOR_TYPE_ROLE,
							m_controlledActor.m_gameId, (int) valuexw);
					sr.show(this, m_controlledActor.m_posX + Tools.random(20),
							m_controlledActor.m_posY - Tools.random(50),
							SkillResult.修为);
				}
				UIWindows.getInstance().m_skill.setXiuwei();
				break;
			case Role.CURRENCY_TYPE_JINGHUN:
				long valuejh = count - DWGameManager.getInstance().m_role.m_jinghun;
				DWGameManager.getInstance().m_role.m_jinghun = count;
				if (valuejh > 0) {
					SkillResult sr = new SkillResult(
							GameActorConstants.ACTOR_TYPE_ROLE,
							m_controlledActor.m_gameId, (int) valuejh);
					sr.show(this, m_controlledActor.m_posX + Tools.random(20),
							m_controlledActor.m_posY - Tools.random(50),
							SkillResult.精魂);
				}
				break;
			case Role.CURRENCY_TYPE_RONGYU:
				long value = count - DWGameManager.getInstance().m_role.m_rongyu;
				DWGameManager.getInstance().m_role.m_rongyu = count;
				if (value > 0) {
					SkillResult sr = new SkillResult(
							GameActorConstants.ACTOR_TYPE_ROLE,
							m_controlledActor.m_gameId, (int) value);
					sr.show(this, m_controlledActor.m_posX + Tools.random(20),
							m_controlledActor.m_posY - Tools.random(50),
							SkillResult.荣誉);
				}
				break;
		}
	}

	private void recvRoleExp(DataInputStream dis) throws IOException
	{
		long curExp = dis.readLong();
		long exp = curExp - DWGameManager.getInstance().m_role.m_exp;
		DWGameManager.getInstance().m_role.m_exp = curExp;
		if (UIWindows.getMain() != null) {
			UIWindows.getMain().updateExp();
		}
		if (exp > 0) {
			SkillResult sr = new SkillResult(
					GameActorConstants.ACTOR_TYPE_ROLE,
					m_controlledActor.m_gameId, (int) exp);
			sr.show(this, m_controlledActor.m_posX + Tools.random(20),
					m_controlledActor.m_posY - Tools.random(50), SkillResult.经验);
		}
		Tools.debugPrintln("当前玩家获得经验 : "
				+ DWGameManager.getInstance().m_role.m_exp);
	}

	/**
	 * 接收额外伤害数值
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvExtraDamage(DataInputStream dis) throws IOException
	{
		int type = dis.readByte();
		long id = dis.readLong();
		int value = dis.readInt();
		GameActor actor = getGameActorByID(type, id);
		if (actor != null) {
			SkillResult sr = new SkillResult(type, id, value);
			sr.show(this, actor.m_posX, actor.m_posY + actor.m_activeBox[1]);
		}
	}

	/**
	 * 互动打断指令
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvNPCInteractBreak(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("读取互动任务打断指令!" + m_interact_start);
		if (m_interact_start) {
			endNPCInteract();
			DWGameManager.getInstance().m_role.stopCasting();
			DWGameManager.getInstance().m_role.stopCastingDescription();
		}
	}

	public byte m_read_spell_type;

	/**
	 * 读取NPC互动任务
	 *
	 * @param dis
	 */
	public void recvNPCInteract(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		m_read_spell_type = dis.readByte();
		Tools.debugPrintln("读条类型 : " + m_read_spell_type);
		int role_act_id = dis.readInt();
		Tools.debugPrintln("玩家动作ID : " + role_act_id);
		int npc_act_id = dis.readInt();
		Tools.debugPrintln("NPC动作ID : " + npc_act_id);
		int time = dis.readInt();
		Tools.debugPrintln("互动时间 : " + time);
		String msg = dis.readUTF();
		Tools.debugPrintln("互动信息 : " + msg);
		DWGameManager.getInstance().m_role
				.stay(DWGameManager.getInstance().m_role.m_direct);
		DWGameManager.getInstance().m_role.setAction(role_act_id, true);
		if (DWGameManager.getInstance().m_role.m_targetActor != null) {
			DWGameManager.getInstance().m_role.m_targetActor.setAction(
					npc_act_id, true);
		}
		DWGameManager.getInstance().m_role.startCasting(time);
		DWGameManager.getInstance().m_role.startCastingDescription(msg);
		startNPCInteract(time * DWGameManager.FRAME_PER_SECOND);
	}

	public DWDialogMenu m_dwDMNPCTaskList;
	public Vector<Task> m_npc_task = new Vector<Task>();
	public Vector<Function> m_npc_function = new Vector<Function>();

	/**
	 * 读取NPC列表信息
	 *
	 * @param dis
	 * @throws IOException
	 */
	public void recvNPCList(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		short state = dis.readShort();
		Tools.debugPrintln("state = " + state);
		if (state == 0) {
			Tools.debugPrintln("读取NPC信息失败!");
		}
		else if (state == 2) {
			long id = dis.readLong();
			if (id > 0) {
				// GameManager.getInstance().m_game_message.sendScenePathfinding(key);
				Npc npc = ((Scene) DWGameManager.getInstance().getGameHandler())
						.getNPCByID(id);
				if (npc != null) {
					// DWGameManager.getInstance().m_role.findPathToTarget(npc);
				}
				Tools.debugPrintln("距离过远寻路到 : " + id);
			}
			else {
				Tools.debugPrintln("距离过远id为0!");
			}
		}
		else {
			String m_npc_name = dis.readUTF();
			String m_npc_dialog = dis.readUTF();
			String headUrl = dis.readUTF();
			byte taskListSize = dis.readByte();// /任务列表长度
			Tools.debugPrintln("name = " + m_npc_name);
			Tools.debugPrintln("dialog = " + m_npc_dialog);
			Tools.debugPrintln("headUrl = " + headUrl);
			Tools.debugPrintln("taskList size = " + taskListSize);
			if (m_npc_task == null) {
				m_npc_task = new Vector<Task>();
			}
			else {
				m_npc_task.removeAllElements();
			}
			if (taskListSize > 0) {
				for (int i = 0; i < taskListSize; i++) {
					Task task = new Task();
					String taskKey = dis.readUTF();// 任务ID
					String taskName = dis.readUTF();// 任务名称
					byte taskState = dis.readByte();// 任务状态
					// byte type = dis.readByte();// 任务类型
					task.m_key = taskKey;
					task.m_name = taskName;
					task.m_status = taskState;
					// task.m_type = type;
					Tools.debugPrintln("taskId[" + i + "].taskID = " + taskKey);
					Tools.debugPrintln("taskId[" + i + "].taskName = "
							+ taskName);
					Tools.debugPrintln("taskId[" + i + "].taskState = "
							+ taskState);
					m_npc_task.addElement(task);
				}
			}
			byte funListSize = dis.readByte();// 功能列表长度
			Tools.debugPrintln("funList size = " + funListSize);
			if (m_npc_function == null) {
				m_npc_function = new Vector<Function>();
			}
			else {
				m_npc_function.removeAllElements();
			}
			if (funListSize > 0) {
				for (int i = 0; i < funListSize; i++) {
					Function function = new Function();
					function.m_name = dis.readUTF();// 功能名称
					function.m_instruct = dis.readInt();// 功能指令ID
					function.m_id_utf = dis.readUTF();// 功能附带数据ID
					Tools.debugPrintln("funName[" + i + "].funName = "
							+ function.m_name);
					Tools.debugPrintln("funName[" + i + "].instruct = "
							+ function.m_instruct);
					Tools.debugPrintln("funName[" + i + "].id = "
							+ function.m_id_utf);
					m_npc_function.addElement(function);
				}
			}

			String[] npclistData = getNPCListData(m_npc_task, m_npc_function);
			m_dwDMNPCTaskList = new DWDialogMenu(m_npc_name, m_npc_dialog,
					npclistData);
			DWControlsManager.getInstance().removeOtherControl();
			DWControlsManager.getInstance().addControl(m_dwDMNPCTaskList);
			m_dwDMNPCTaskList.addListener(new DWListener() {

				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					DWControlsManager.getInstance().removeControl(
							m_dwDMNPCTaskList);
					if (m_npc_task == null && m_npc_task.size() > 0) {
						Tools.debugPrintln("getNPCListListener m_npc_task is null!");
					}
					if (m_npc_function == null && m_npc_function.size() > 0) {
						Tools.debugPrintln("getNPCListListener m_npc_function is null!");
					}

					int index = m_dwDMNPCTaskList.getMenusIndex();
					Tools.debugPrintln("NPC列表选择index : " + index);
					if (m_npc_task == null && m_npc_task.size() > 0) {
						Function func = (Function) m_npc_function
								.elementAt(index);
						if (func != null) {
							DWGameManager
									.getInstance()
									.getSendMessage()
									.sendFunction(func.m_instruct,
											func.m_id_utf);
						}
					}
					else {
						if (index >= m_npc_task.size()) {
							Function func = (Function) m_npc_function
									.elementAt(index - m_npc_task.size());
							if (func != null) {
								DWGameManager
										.getInstance()
										.getSendMessage()
										.sendFunction(func.m_instruct,
												func.m_id_utf);
								// DWControlsManager.getInstance().removeControl(ddm);
							}
						}
						else {
							Task task = (Task) m_npc_task.elementAt(index);
							// m_npc_operate_id = index;
							if (task != null) {
								DWGameManager.getInstance().getSendMessage()
										.sendNPCTaskView(task.m_key);
							}
						}
					}
				}
			});
		}
	}

	// public void m_dwDMNPCTaskListRefresh(){
	// if (m_dwDMNPCTaskList!=null) {
	// String[] npclistData = getNPCListData(m_npc_task, m_npc_function);
	// m_dwDMNPCTaskList.setMenus(npclistData);
	// }
	// }
	/**
	 * 得到NPC列表数据
	 *
	 * @return
	 */
	public String[] getNPCListData(Vector m_npc_task, Vector m_npc_function)
	{
		int len = 0;
		String[] npcList = null;
		if (m_npc_task != null && m_npc_task.size() > 0) {
			len += m_npc_task.size();
		}
		if (m_npc_function != null && m_npc_function.size() > 0) {
			len += m_npc_function.size();
		}
		if (len > 0) {
			npcList = new String[len];
			int k = 0;
			if (m_npc_task != null && m_npc_task.size() > 0) {
				for (int i = 0; i < m_npc_task.size(); i++) {
					Task task = (Task) m_npc_task.elementAt(i);
					npcList[k] = "<mark c="
							+ task.TASK_NAME_COLOR_STR[task.m_status] + ">"
							+ task.TASK_STATUS[task.m_status] + "</mark>"
							+ task.m_name;
					Tools.debugPrintln("添加NPC列表 : " + npcList[k]);
					k++;
				}
			}
			if (m_npc_function != null && m_npc_function.size() > 0) {
				for (int i = 0; i < m_npc_function.size(); i++) {
					Function func = (Function) m_npc_function.elementAt(i);
					npcList[k] = func.m_name;
					Tools.debugPrintln("添加NPC列表 : " + npcList[k]);
					k++;
				}
			}
		}
		return npcList;
	}

	/**
	 * 更新NPC头上状态
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvSceneNPCStatus(DataInputStream dis) throws IOException
	{
		short size = dis.readShort();// 数量
		if (size > 0) {
			// m_refresh_thumbnail = false;
			// m_thumbnail_list.removeAllElements();
			for (short i = 0; i < size; i++) {
				long npcID = dis.readLong();// id
				short x = dis.readShort();
				short y = dis.readShort();
				byte type = dis.readByte();// 类型
				byte faction = dis.readByte();// 阵营
				int status = dis.readInt();// 状态
				byte function = dis.readByte();
				String headtips = dis.readUTF();
				Npc npc = getNPCByID(npcID);
				if (npc == null) {
					npc = new Npc();
					npc.m_type = type;
					npc.m_posX = x;
					npc.m_posY = y;
				}
				npc.m_head_state = status;
				npc.m_function_icon = function;
				npc.m_head_tips = headtips;
				npc.m_faction = faction;
				if (npc.m_type == GameActorConstants.ACTOR_TYPE_NPC
						|| npc.m_type == GameActorConstants.ACTOR_TYPE_GATE) {
					// int search_w = m_bg.m_columns * m_bg.m_tileW;
					// int search_h = m_bg.m_rows * m_bg.m_tileH;
					// int scaling_w = search_w / (THUMBNAIL_SHOW_WIDTH - 6);
					// int scaling_h = search_h / (THUMBNAIL_SHOW_HEIGHT - 6);
					if (npc.m_type == GameActorConstants.ACTOR_TYPE_NPC) {
						if (npc.checkTargetFriend(DWGameManager.getInstance().m_role)) {
							// npc.m_thumbnail_color = Tools.YELLOW;
						}
						else {
							// npc.m_thumbnail_color = Tools.RED;
						}
					}
					else if (npc.m_type == GameActorConstants.ACTOR_TYPE_GATE) {
						// npc.m_thumbnail_color = Tools.BLUE;
					}
					// npc.m_thumbnail_x = npc.m_posX / scaling_w + 3;
					// npc.m_thumbnail_y = npc.m_posY / scaling_h + 3;
					// m_thumbnail_list.addElement(npc);
				}
			}
			// m_refresh_thumbnail = true;
		}
	}

	/**
	 * 世界寻路
	 *
	 * @param dis
	 * @throws IOException
	 */
	public void recvScenePathfinding(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		short status = dis.readShort();
		String msg = dis.readUTF();
		if (status == 1) {
			Role role = DWGameManager.getInstance().m_role;
			if (role.isAliveStatus()) {
				role.clearPathfinding();
				role.m_pathfinding_id = dis.readLong();
				int size = dis.readInt();
				if (size > 0) {
					role.m_pathfinding_label = 0;
					Tools.debugPrintln("坐标长度 : " + size);
					PointF[] points = new PointF[size];
					for (int i = 0, x = 0, y = 0; i < size; i++) {
						x = dis.readInt();
						y = dis.readInt();
						PointF Point = new PointF(x, y);
						points[i] = Point;
						Tools.debugPrintln("第" + i + "维 : " + x + " : " + y);
					}
					if (points != null && points.length != 0) {
						role.doPath(points);
					}
				}
				DWGameManager.getInstance().m_role.stay(DWGameManager
						.getInstance().m_role.m_direct);
				if (DWControlsManager.getInstance().contains(
						UIWindows.getInstance().m_renwu.m_rw_Frame)) {
					if (UIWindows.getInstance().m_renwu.m_rw_Frame != null) {
						DWControlsManager.getInstance().removeControl(
								UIWindows.getInstance().m_renwu.m_rw_Frame);
					}
				}
				Tools.debugPrintln("读取寻路成功!" + role.m_pathfinding_id);
			}
		}
		else {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_A, msg);
		}
	}

	// ////////////////////////////////////////////////////////////////
	// // 光效相关
	public static final int EFFECT_MAX_NUM = 50;
	public CopyOnWriteArrayList<GameEffect> m_effects = new CopyOnWriteArrayList<GameEffect>();

	/**
	 * 添加光效
	 *
	 * @param x
	 * @param y
	 */
	public GameEffect addEffect(int id, int srcx, int srcy, int destx,
			int desty, boolean flipX)
	{
		if (id < 0)
			return null;
		GameEffect effect = null;
		if (m_effects.size() < EFFECT_MAX_NUM) {
			effect = (GameEffect) (GameEffect.s_effect.clone());
			effect.init(this, srcx, srcy, destx, desty, id, true,
					GameEffect.DURATION_NONE, flipX);
			m_effects.add(effect);
			return effect;
		}
		int index = getEarliestEffect();
		effect = (GameEffect) (GameEffect.s_effect.clone());
		effect.init(this, srcx, srcy, destx, desty, id, true,
				GameEffect.DURATION_NONE, flipX);
		m_effects.set(index, effect);
		return effect;
	}

	public GameEffect addEffect(int id, int srcx, int srcy, int destx,
			int desty, int duration, boolean flipX)
	{
		if (id < 0)
			return null;
		GameEffect effect = null;
		if (m_effects.size() < EFFECT_MAX_NUM) {
			effect = (GameEffect) (GameEffect.s_effect.clone());
			effect.init(this, srcx, srcy, destx, desty, id, true, duration,
					flipX);
			m_effects.add(effect);
			return effect;
		}
		int index = getEarliestEffect();
		effect = (GameEffect) (GameEffect.s_effect.clone());
		effect.init(this, srcx, srcy, destx, desty, id, true, duration, flipX);
		m_effects.set(index, effect);
		return effect;
	}

	/**
	 * 移除最早的光效
	 */
	public int getEarliestEffect()
	{
		int frameLeft = Integer.MAX_VALUE;
		int index = -1;
		GameEffect effect;
		for (int i = 0; i < m_effects.size(); i++) {
			effect = (GameEffect) m_effects.get(i);
			if (!effect.m_enabled) {
				return i;
			}
			if (effect.getFrameLeft() < frameLeft) {
				frameLeft = effect.getFrameLeft();
				index = i;
			}
		}
		return index;
	}

	/**
	 * 根据类型和ID获得Actor
	 */
	public GameActor getGameActorByID(int type, long id)
	{
		switch (type) {
			case GameActorConstants.ACTOR_TYPE_ROLE:
				return getRoleByID(id);
			default:
				return getNPCByID(id);
		}
	}

	private void recvAddActor2(DataInputStream dis) throws IOException
	{
		short count = dis.readShort();// 读取添加角色数量
		Map<Long, GameActor> actors = new HashMap<Long, GameActor>();
		for (int i = 0; i < count; i++) {
			try {
				long gameID = dis.readLong();// 读取添加ID
				byte type = dis.readByte();// 读取类型
				byte faction = dis.readByte();// 读取阵营
				byte flag = dis.readByte(); //
				byte vocation = dis.readByte();// 读取职业
				byte sex = dis.readByte();// 读取性别
				String name = dis.readUTF();// 读取昵称
				short level = dis.readShort();// 读取等级
				byte status = dis.readByte();// 读取状态
				int action = dis.readInt();// 读取行为
				short attacked_range = dis.readShort(); // 受创半径
				int hp = dis.readInt();// 读取当前生命值
				int hpMax = dis.readInt();// 读取最大生命值
				int mp = dis.readInt();// 读取当前魔法值
				int mpMax = dis.readInt();// 读取最大魔法值
				byte anger = 0;
				byte angerMax = 0;
				if (type == GameActorConstants.ACTOR_TYPE_ROLE) {
					anger = dis.readByte();
					angerMax = dis.readByte();
				}

				byte resCount = dis.readByte();// 资源个数
				String[] urls = new String[resCount];
				String temp;
				for (int j = 0; j < resCount; j++) {
					temp = dis.readUTF();
					if (temp.length() == 0) {
						temp = null;
					}
					urls[j] = temp;
				}

				int speed = dis.readShort();// 速度
				short posX = dis.readShort();// 坐标X
				short posY = dis.readShort();// 坐标Y
				short actionId = dis.readShort();// 动作ID

				// 角色特有
				byte vip_lv = 0;
				byte wanted = -1;
				String petUrl = null;
				String petName = null;
				String family = null;
				byte appellation_color = 0;
				String appellation = null;
				byte app_type = 0;
				String sellTitle = null;
				if (type == GameActorConstants.ACTOR_TYPE_ROLE) {
					family = dis.readUTF();
					vip_lv = dis.readByte();
					wanted = dis.readByte();
					petUrl = dis.readUTF();
					petName = dis.readUTF();
					Tools.debugPrintln("petUrl=" + petUrl + ":petName="
							+ petName);
					appellation_color = dis.readByte();
					appellation = dis.readUTF();
					app_type = dis.readByte();
					sellTitle = dis.readUTF();
				}

				if (type == GameActorConstants.ACTOR_TYPE_ROLE) {
					Role role = getRoleByID(gameID);

					if (role == null) {
						role = new Role();
						role.m_type = type;
						role.m_gameId = gameID;
					}

					role.m_faction = faction;
					role.m_actor_flag = flag;
					role.m_vip_lv = vip_lv;
					role.m_wanted_type = wanted;
					role.m_family_name = family;
					role.m_vocation = vocation;
					role.m_sellTitle = sellTitle;
					// role.m_race = race;
					role.m_sex = sex;
					role.m_name = name;
					role.m_lv = level;
					role.m_status = status;
					role.m_action = action;
					role.m_underAttack_range = attacked_range;
					role.m_hp = hp;
					role.m_hpMax = hpMax;
					role.m_mp = mp;
					role.m_mpMax = mpMax;
					role.m_anger = anger;
					role.m_angerMax = angerMax;
					role.m_appellation_color = appellation_color;
					role.m_appellation = appellation;
					role.m_appType = app_type;
					role.initAppAnim();
					role.m_anims = new Animation[resCount];
					role.m_refsResHead = new ResHead[resCount];
					role.m_velocity = speed
							/ (float) DWGameManager.FRAME_PER_SECOND;

					if (role.m_refsResHead == null)
						role.m_refsResHead = new ResHead[resCount];
					if (role.m_anims == null)
						role.m_anims = new Animation[resCount];

					for (int j = 0; j < resCount; j++) {
						String resName = role.getFigureName(j, urls[j]);
						if (resName == null) {
							role.m_refsResHead[j] = null;
							role.m_anims[j] = null;
							continue;
						}
						int resType = DWSerializableFactory.RESOURCE_TYPE_ANIM;
						String resUrl = new StringBuffer()
								.append(DWSerializableFactory.DIR_ANIM)
								.append(resName)
								.append(DWSerializableFactory.EXTENSION_ANIM)
								.toString();
						int resVersion = 1;
						ResHead head = new ResHead(resType, resUrl, resVersion);
						role.m_refsResHead[j] = head;
						if (role.m_anims[j] == null
								|| !role.m_anims[j].m_resHead
										.equals(role.m_refsResHead[j])) {
							role.m_anims[j] = (Animation) (ResourceManager
									.getInstance()
									.loadResource(
											DWGameManager.getInstance().m_resourceDynamic,
											role.m_refsResHead[j]));
						}
					}

					role.m_anim = role.m_anims[Role.ANIM_HEAD];

					// 坐骑相关
					if (role.m_refsResHead[Role.ANIM_RIDE] == null) {
						role.m_isride = false;
						role.m_ride = null;
					}
					else {
						role.m_isride = true;
						if (role.m_ride != null) {
							role.m_ride.dispose();
							role.m_ride = null;
						}
						role.m_ride = new Actor(role.m_anims[Role.ANIM_RIDE]);
					}

					if (role.m_refsResHead.length > Role.ANIM_EFFECT1) {
						// 角色身上的宝石光效
						if (role.m_refsResHead[Role.ANIM_EFFECT1] == null) {
							role.m_effect1 = null;
						}
						else {
							if (role.m_effect1 != null) {
								role.m_effect1.dispose();
								role.m_effect1 = null;
							}
							role.m_effect1 = new Actor(
									role.m_anims[Role.ANIM_EFFECT1]);
						}
					}

					if (role.m_refsResHead.length > Role.ANIM_EFFECT2) {
						// 角色身上的武器强化光效
						if (role.m_refsResHead[Role.ANIM_EFFECT2] == null) {
							role.m_effect2 = null;
						}
						else {
							if (role.m_effect2 != null) {
								role.m_effect2.dispose();
								role.m_effect2 = null;
							}
							role.m_effect2 = new Actor(
									role.m_anims[Role.ANIM_EFFECT2]);
						}
					}

					role.clearFlex();
					role.m_posX = posX;
					role.m_posY = posY;

					if (role.m_status == Role.ACTOR_STATUS_DEAD) {
						role.setAction(Role.ACTION_DEAD * Role.DIRECT_NUM, 0,
								0, false, true);
						role.setFrame(role.m_anim.m_actions[Role.ACTION_DEAD
								* Role.DIRECT_NUM].length - 1);
					}
					else {
						role.stay(role.m_direct);
					}
					if (petUrl != null && !petUrl.equals("")) {
						// TODO
						Tools.debugPrintln("petURL aaaaaaaaaaaaaaaaaaaaaaaaaaa");
						role.m_pet = creatPet(role, petUrl, petName);
					}
					role.activate();
					actors.put(role.m_gameId, role);
				}
				else if (type == GameActorConstants.ACTOR_TYPE_ITEM
						|| type == GameActorConstants.ACTOR_TYPE_PET) { // 掉落道具
					Npc npc = getNPCByID(gameID);

					if (npc == null) {
						npc = new Npc();
						npc.m_type = type;
						npc.m_gameId = gameID;
					}

					npc.m_collideBox[0] = -30;
					npc.m_collideBox[1] = -13;
					npc.m_collideBox[2] = 30;
					npc.m_collideBox[3] = 13;
					npc.m_activeBox[0] = -30;
					npc.m_activeBox[1] = -90;
					npc.m_activeBox[2] = 30;
					npc.m_activeBox[3] = 10;

					npc.m_faction = faction;
					npc.m_actor_flag = flag;
					npc.m_name = name;
					npc.m_lv = level;
					npc.m_status = status;
					npc.m_action = action;
					npc.m_underAttack_range = attacked_range;
					npc.m_hp = hp;
					npc.m_hpMax = hpMax;
					npc.m_mp = mp;
					npc.m_mpMax = mpMax;
					npc.m_anims = new Animation[resCount];
					npc.m_refsResHead = new ResHead[resCount];
					for (int j = 0; j < resCount; j++) {
						npc.m_refsResHead[j] = new ResHead();
						npc.m_refsResHead[j].m_type = DWSerializableFactory.RESOURCE_TYPE_ANIM;// 读取动画资源类型
						npc.m_refsResHead[j].m_url = new StringBuffer(
								DWSerializableFactory.DIR_ANIM).append(urls[j])
								.append(DWSerializableFactory.EXTENSION_ANIM)
								.toString();// 读取动画资源URL
						npc.m_refsResHead[j].m_version = 1;// 读取动画资源版本
						npc.m_anims[j] = (Animation) (ResourceManager
								.getInstance().loadResource(
								DWGameManager.getInstance().m_resourceDynamic,
								npc.m_refsResHead[j]));
					}
					npc.m_anim = npc.m_anims[0];
					npc.clearFlex();
					npc.m_posX = posX;
					npc.m_posY = posY;
					npc.m_velocity = speed
							/ (float) DWGameManager.FRAME_PER_SECOND;
					npc.setAction(actionId, true);
					npc.activate();
					actors.put(npc.m_gameId, npc);
				}
				else { // npc
						// Tools.debugPrintln("同屏添加NPCID : " + gameID+"");
					Npc npc = getNPCByID(gameID);
					ResHead head = new ResHead();
					head.m_type = DWSerializableFactory.RESOURCE_TYPE_NPC;
					head.m_url = new StringBuffer(DWSerializableFactory.DIR_AC)
							.append(urls[0])
							.append(DWSerializableFactory.EXTENSION_AC)
							.toString();// 读取角色动画资源URL
					head.m_version = 1;
					Npc model = (Npc) ResourceManager
							.getInstance()
							.loadResource(
									DWGameManager.getInstance().m_resourceDynamic,
									head);
					if (npc == null) {
						if (model == null) {
							Tools.debugPrintln("场景文件中缺失NPC数据： NPC url = "
									+ head.m_url);
							continue;
						}
						else {
							npc = (Npc) model.clone();
						}
						npc.m_type = type;
						npc.m_gameId = gameID;
					}
					else {
						npc.copy(model);
					}

					npc.m_faction = faction;
					npc.m_actor_flag = flag;
					npc.m_name = name;
					npc.m_lv = level;
					npc.m_status = status;
					npc.m_action = action;
					npc.m_underAttack_range = attacked_range;
					npc.m_hp = hp;
					npc.m_hpMax = hpMax;
					npc.m_mp = mp;
					npc.m_mpMax = mpMax;
					npc.m_anim = npc.m_anims[0];
					npc.clearFlex();
					npc.m_posX = posX;
					npc.m_posY = posY;
					npc.m_velocity = speed
							/ (float) DWGameManager.FRAME_PER_SECOND;
					if (npc.m_status == Npc.ACTOR_STATUS_DEAD) {
						npc.setAction(Npc.ACTION_DEAD * Npc.DIRECT_NUM, 0, 0,
								false, true);
						npc.setFrame(npc.m_anim.m_actions[Npc.ACTION_DEAD
								* Npc.DIRECT_NUM].length - 1);
					}
					else {
						npc.setAction(actionId, true);
					}
					npc.activate();
					actors.put(npc.m_gameId, npc);
				}
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}

		addDynamicActors(actors);
	}

	private Npc creatPet(Role role, String url, String name)
	{
		if (url == null) {
			return null;
		}
		if (name == null) {
			name = "";
		}
		Npc npc = new Npc();
		npc.m_type = GameActorConstants.ACTOR_TYPE_PET;
		npc.m_collideBox[0] = -30;
		npc.m_collideBox[1] = -13;
		npc.m_collideBox[2] = 30;
		npc.m_collideBox[3] = 13;
		npc.m_activeBox[0] = -30;
		npc.m_activeBox[1] = -90;
		npc.m_activeBox[2] = 30;
		npc.m_activeBox[3] = 10;
		npc.m_name = name;
		npc.m_layer = role.m_layer;
		npc.m_scene = role.m_scene;
		npc.m_status = Npc.ACTOR_STATUS_FREE;
		npc.m_action = Npc.ACTION_STAND;
		npc.m_underAttack_range = 0;
		npc.m_hp = 1;
		npc.m_hpMax = 1;
		npc.m_mp = 1;
		npc.m_mpMax = 1;
		npc.m_anims = new Animation[1];
		npc.m_refsResHead = new ResHead[1];
		npc.m_refsResHead[0] = new ResHead();
		npc.m_refsResHead[0].m_type = DWSerializableFactory.RESOURCE_TYPE_ANIM;// 读取动画资源类型
		npc.m_refsResHead[0].m_url = new StringBuffer(
				DWSerializableFactory.DIR_ANIM).append(url)
				.append(DWSerializableFactory.EXTENSION_ANIM).toString();// 读取动画资源URL
		npc.m_refsResHead[0].m_version = 1;// 读取动画资源版本
		npc.m_anims[0] = (Animation) (ResourceManager.getInstance()
				.loadResource(DWGameManager.getInstance().m_resourceDynamic,
						npc.m_refsResHead[0]));

		npc.m_anim = npc.m_anims[0];
		npc.clearFlex();
		npc.m_posX = role.m_posX;
		npc.m_posY = role.m_posY;
		npc.m_velocity = role.m_velocity;
		npc.setAction(Npc.ACTION_STAND, true);
		npc.activate();
		return npc;
	}

	private void recvUpdateActorPosition2(DataInputStream dis)
			throws IOException
	{
		short count = dis.readShort();
		Map<Long, GameActor> actors = new Hashtable<Long, GameActor>();
		ArrayList<GameActor> missActors = new ArrayList<GameActor>();
		for (int i = 0; i < count; i++) {
			try {
				long id = dis.readLong();
				byte type = dis.readByte();
				short x = dis.readShort();
				short y = dis.readShort();
				GameActor actor = getGameActorByID(type, id);
				if (actor == null) {
					switch (type) {
						case GameActorConstants.ACTOR_TYPE_ROLE:
							actor = new Role();
							break;
						default:
							actor = new Npc();
							break;
					}
					if (actor != null) {
						actor.m_type = type;
						actor.m_gameId = id;
						missActors.add(actor);
					}
				}
				actor.activate();
				actor.addFlex(new Point(x, y));
				actors.put(actor.m_gameId, actor);
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}
		if (missActors.size() > 0) {
			DWGameManager.getInstance().getSendMessage()
					.sendSceneUpdateDeficiency(missActors);
		}
		// m_dynamicActors.clear();
		deactiveDynamicActors(actors);
		addDynamicActors(actors);
	}

	private void recvUpdateActorData2(DataInputStream dis) throws IOException
	{
		short count = dis.readShort();
		for (int i = 0; i < count; i++) {
			try {
				long id = dis.readLong();
				byte type = dis.readByte();
				int hp = dis.readInt();
				int hpMax = dis.readInt();
				int mp = dis.readInt();
				int mpMax = dis.readInt();
				byte anger = 0;
				byte angerMax = 0;
				GameActor actor = getGameActorByID(type, id);
				if (type == GameActorConstants.ACTOR_TYPE_ROLE) {
					anger = dis.readByte();
					angerMax = dis.readByte();
				}
				if (actor != null) {
					actor.m_hp = hp;
					actor.m_hpMax = hpMax;
					actor.m_mp = mp;
					actor.m_mpMax = mpMax;
					if (type == GameActorConstants.ACTOR_TYPE_ROLE) {
						((Role) actor).m_anger = anger;
						((Role) actor).m_angerMax = angerMax;
						// if (actor == m_controlledActor && anger == 0) {
						// UIWindows.getMain().resetDazhao();
						// }
					}
					actor.setAttr(Attribute.MAX_HP, actor.m_hpMax);
					actor.setAttr(Attribute.MAX_MP, actor.m_mpMax);
					if (actor == m_controlledActor) {
						UIWindows.getMain().updateMyHead();
					}
					else if (m_controlledActor.m_targetActor != null
							&& actor == m_controlledActor.m_targetActor) {
						UIWindows.getMain().updateTargetHead();
					}

				}
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}
	}

	private void recvUpdateActorFigure2(DataInputStream dis) throws IOException
	{
		short count = dis.readShort();// 读取更新角色的数量
		for (int i = 0; i < count; i++) {
			try {
				long id = dis.readLong();// 读取更新ID
				byte type = dis.readByte();// 读取类型
				byte resCount = dis.readByte();// 读资源个数
				String[] urls = new String[resCount];
				String temp;

				for (int j = 0; j < resCount; j++) {
					temp = dis.readUTF();
					if (temp.length() == 0) {
						temp = null;
					}
					urls[j] = temp;// 动画URL
				}

				int speed = dis.readShort();// 角色速度

				byte vip = 0;
				byte wanted = -1;
				String petUrl = null;
				String petName = null;
				String appellation = null;
				String family = null;
				byte app_type = 0;
				String sellTitle = null;
				byte appellation_color = 0;
				if (type == GameActorConstants.ACTOR_TYPE_ROLE) {
					family = dis.readUTF();
					vip = dis.readByte();
					wanted = dis.readByte();
					petUrl = dis.readUTF();
					petName = dis.readUTF();
					appellation_color = dis.readByte();
					appellation = dis.readUTF();
					app_type = dis.readByte();
					sellTitle = dis.readUTF();
				}

				if (type == GameActorConstants.ACTOR_TYPE_ROLE) {// 更新动态角色
					Role role = getRoleByID(id);
					if (role == null) {
						Tools.debugPrintln("更新角色形象失败 ,无法找到该角色--id:" + id);
						continue;
					}
					role.m_appellation_color = appellation_color;
					role.m_appellation = appellation;
					role.m_appType = app_type;
					role.initAppAnim();
					role.m_vip_lv = vip;
					role.m_wanted_type = wanted;
					role.m_family_name = family;
					role.m_sellTitle = sellTitle;
					if (role.m_refsResHead == null)
						role.m_refsResHead = new ResHead[resCount];
					if (role.m_anims == null)
						role.m_anims = new Animation[resCount];
					for (int j = 0; j < resCount; j++) {
						String resName = role.getFigureName(j, urls[j]);
						if (resName == null) {
							role.m_refsResHead[j] = null;
							role.m_anims[j] = null;
							continue;
						}
						int resType = DWSerializableFactory.RESOURCE_TYPE_ANIM;
						String resUrl = new StringBuffer()
								.append(DWSerializableFactory.DIR_ANIM)
								.append(resName)
								.append(DWSerializableFactory.EXTENSION_ANIM)
								.toString();
						int resVersion = 1;
						ResHead head = new ResHead(resType, resUrl, resVersion);
						role.m_refsResHead[j] = head;
						if (role.m_anims[j] == null
								|| !role.m_anims[j].m_resHead
										.equals(role.m_refsResHead[j])) {
							role.m_anims[j] = (Animation) (ResourceManager
									.getInstance()
									.loadResource(
											DWGameManager.getInstance().m_resourceDynamic,
											role.m_refsResHead[j]));
						}

					}
					role.m_anim = role.m_anims[Role.ANIM_HEAD];
					// 坐骑相关
					if (role.m_refsResHead[Role.ANIM_RIDE] == null) {
						role.m_isride = false;
						role.m_ride = null;
					}
					else {
						role.m_isride = true;
						if (role.m_ride != null) {
							role.m_ride.dispose();
							role.m_ride = null;
						}
						role.m_ride = new Actor(role.m_anims[Role.ANIM_RIDE]);
					}

					if (role.m_refsResHead.length > Role.ANIM_EFFECT1) {
						// 角色身上的光效
						if (role.m_refsResHead[Role.ANIM_EFFECT1] == null) {
							role.m_effect1 = null;
						}
						else {
							if (role.m_effect1 != null) {
								role.m_effect1.dispose();
								role.m_effect1 = null;
							}
							role.m_effect1 = new Actor(
									role.m_anims[Role.ANIM_EFFECT1]);
						}
					}

					if (role.m_refsResHead.length > Role.ANIM_EFFECT2) {
						// 角色身上的武器强化光效
						if (role.m_refsResHead[Role.ANIM_EFFECT2] == null) {
							role.m_effect2 = null;
						}
						else {
							if (role.m_effect2 != null) {
								role.m_effect2.dispose();
								role.m_effect2 = null;
							}
							role.m_effect2 = new Actor(
									role.m_anims[Role.ANIM_EFFECT2]);
						}
					}

					role.setAttr(Attribute.SPEED, speed);
					role.m_velocity = speed
							/ (float) DWGameManager.FRAME_PER_SECOND;

					if (role.m_status == Role.ACTOR_STATUS_DEAD) {
						role.setAction(Role.ACTION_DEAD * Role.DIRECT_NUM, 0,
								0, false, true);
						role.setFrame(role.m_anim.m_actions[Role.ACTION_DEAD
								* Role.DIRECT_NUM].length - 1);
					}
					else {
						role.stay(role.m_direct);
					}
					if (petUrl != null && !petUrl.equals("")) {
						String url = new StringBuffer(
								DWSerializableFactory.DIR_ANIM).append(petUrl)
								.append(DWSerializableFactory.EXTENSION_ANIM)
								.toString();// 读取动画资源URL
						if (role.m_pet != null) {
							if (!url.equals(role.m_pet.m_anim.m_resHead.m_url)) {
								role.m_pet = creatPet(role, petUrl, petName);
							}
						}
						else {
							role.m_pet = creatPet(role, petUrl, petName);
						}
						url = null;
					}
					else {
						role.m_pet = null;
					}
				}
				else {
					Npc npc = getNPCByID(id);
					if (npc == null) {
						Tools.debugPrintln("更新NPC形象失败 ,无法找到该NPC--id:" + id
								+ "  name:");
						continue;
					}
					npc.setAttr(Attribute.SPEED, speed);
					npc.m_velocity = speed
							/ (float) DWGameManager.FRAME_PER_SECOND;
				}
			}
			catch (Exception ex) {
				Tools.debug(ex);
			}
		}
	}

	/**
	 * 移除Actor
	 *
	 * @param dis
	 * @throws IOException
	 */
	public void recvRemoveActor(DataInputStream dis) throws IOException
	{
		short count = dis.readShort();
		for (int i = 0; i < count; i++) {
			try {
				long id = dis.readLong();// 读取更新ID
				byte type = dis.readByte();// 读取类型
				GameActor actor = removeGameActorById(type, id);
				if (actor != null) {
					actor.destroy();
					Tools.debugPrintln("同屏删除actor:" + actor.toString());
				}
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}
	}

	/**
	 * 更正坐标指令
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvScenePostionRevise(DataInputStream dis) throws IOException
	{

		int type = dis.readByte();
		long id = dis.readLong();
		int x = dis.readShort();
		int y = dis.readShort();
		GameActor actor = getGameActorByID(type, id);
		if (actor != null) {
			actor.m_posX = x;
			actor.m_posY = y;
		}
	}

	/**
	 * 读取升级
	 *
	 * @param
	 */
	public void recvSceneUpgrade(DataInputStream dis) throws IOException
	{
		long id = dis.readLong();
		int level = dis.readInt();
		int maxHP = dis.readInt();
		int maxMP = dis.readInt();
		long exp = dis.readLong();
		long maxExp = dis.readLong();
		Tools.debugPrintln("角色升级 : " + id + " : " + level + " : " + maxHP
				+ " : " + maxMP + " : " + exp + " : " + maxExp);
		Role role = DWGameManager.getInstance().m_role;
		if (id == role.m_gameId) {
			m_controlledActor.m_lv = level;
			m_controlledActor.m_hp = maxHP;
			m_controlledActor.m_hpMax = maxHP;
			m_controlledActor.m_mp = maxMP;
			m_controlledActor.m_mpMax = maxMP;
			role.m_exp = exp;
			role.m_maxExp = maxExp;
			addEffect(15, role.m_posX, role.m_posY, role.m_posX, role.m_posY,
					false);
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateMyHead();
			}
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateLv();
			}
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateExp();
			}
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateOpenIcon();
			}
		}
		else {
			Role player = getRoleByID(id);
			if (player != null) {
				player.m_lv = level;
				player.m_hp = maxHP;
				player.m_hpMax = maxHP;
				player.m_mp = maxMP;
				player.m_mpMax = maxMP;
				player.m_exp = exp;
				player.m_maxExp = maxExp;
				addEffect(15, player.m_posX, player.m_posY, player.m_posX,
						player.m_posY, false);
			}
			else {
				Tools.debugPrintln("没有找到升级玩家!");
			}
		}
		if (id == DWGameManager.getInstance().m_role.m_gameId) {
			addUpgradeAnimAction(m_upgradeAction_rwup);
			DWGameManager.getInstance().getSendMessage()
					.sendTaskacceptablyTaskList();
		}
		m_zhanli_state = true;
	}

	/**
	 * 战力相关
	 */
	public boolean m_zhanli_state = false;

	/**
	 * 更新actor状态
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvUpdateActorStatus(DataInputStream dis) throws IOException
	{
		int size = dis.readByte();
		GameActor actor = null;
		for (int i = 0; i < size; i++) {
			int type = dis.readByte();
			long id = dis.readLong();
			int status = dis.readByte();
			actor = getGameActorByID(type, id);
			if (actor != null) {
				actor.m_status = status;
				if (actor.isDead()) {
					actor.m_dead_time = System.currentTimeMillis();
					// actor.dealDead();
					if (actor == m_controlledActor.m_targetActor) {
						setTargetActor(null);
						m_controlledActor.clearAutoAttack();
					}
					else if (actor == m_controlledActor) {
						UIHook.closeHook();
						m_controlledActor.breakAutoAttack();
						//取消原地复活寻路
						m_controlledActor.clearPathfinding();
						m_controlledActor.clearFlex();
					}
				}
				else {
					actor.stay(actor.m_direct);
				}

			}
		}
	}

	/**
	 * 更新actor行为
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvUpdateActorAction(DataInputStream dis) throws IOException
	{
		int size = dis.readByte();
		GameActor actor = null;
		for (int i = 0; i < size; i++) {
			int type = dis.readByte();
			long id = dis.readLong();
			int action = dis.readInt();
			actor = getGameActorByID(type, id);
			if (actor != null) {
				actor.m_action = action;
				if (actor == m_controlledActor && (action & GameActorConstants.ACTOR_ACTION_FORBIT_MOVE) != 0) {
					m_controlledActor.stay(m_controlledActor.m_direct);
					if (UIWindows.getMain() != null) {
						UIWindows.getMain().stopVer();
					}
				}
			}
		}
	}

	private void recvUpdateActorFlag(DataInputStream dis) throws IOException
	{
		int type = dis.readByte();
		long id = dis.readLong();
		int flag = dis.readByte();
		GameActor actor = getGameActorByID(type, id);
		if (actor != null) {
			actor.m_actor_flag = flag;
		}
	}

	private ArrayList<GameActor> m_update_deficiency = new ArrayList<GameActor>();

	/**
	 * 学习技能
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvLearnCombatSkill(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("收到学习技能指令：" + GameProtocol.SC_LEARN_COMBAT_SKILL);
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_技能);
		int state = dis.readByte();
		if (state == 1) {
			DWGameManager.getInstance().m_role.updateCombatSkill(dis);
			UIWindows.getInstance().m_skill.updateWindow();
			Tools.debugPrintln("学习技能成功");
		}
		else if (state == 0) {
			Tools.debugPrintln("学习技能失败");
		}
	}

	/**
	 * 激活技能
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvActiveCombatSkill(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("收到激活技能指令：" + GameProtocol.SC_ACTIVE_COMBAT_SKILL);
		int state = dis.readByte();
		if (state == 1) {
			int index = dis.readByte();
			String key = dis.readUTF();
			Tools.debugPrintln("recvActiveCombatSkill index=" + index + ";key="
					+ key);
			DWGameManager.getInstance().m_role.recvSetShortcut(key, index);
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().updateSkillSet();
			}
			Tools.debugPrintln("激活技能成功");
		}
		else if (state == 0) {
			Tools.debugPrintln("激活技能失败");
		}
	}

	/**
	 * 施法
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvCastSkill(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("收到施法中断指令：" + GameProtocol.CS_CAST_SKILL);
		// 状态码和描述
		int state = dis.readByte();
		Tools.debugPrintln("施法状态 : " + state);
		if (state != 0) {
			// addMessage(descp, Tools.RED, Tools.BLACK);
			Role role = DWGameManager.getInstance().m_role;
			role.stay(role.m_direct);
			// CD重置
			if (role.m_curCombatSkill != null) {
				((RoleCombatSkill) role.m_curCombatSkill).m_lastUsedTime = 0;
				role.m_curCombatSkill.deactive();
				role.m_curCombatSkill = null;
			}
			// 停止施法
			role.m_isCasting = false;
			role.stopCasting();
			role.stopCastingDescription();
			role.clearAutoAttack();
			// role.setAction(Role.ACTION_STAND * Role.DIRECT_NUM +
			// role.m_direct, 0, 0, true, false);
		}
	}

	// 摆摊接收是否成功
	public void recvBaitanResult(DataInputStream dis)
	{

		try {
			byte state = dis.readByte();

			switch (state) {
				case 0:

					break;
				case 1:
					UIWindows.getInstance().m_baitan.open((byte) 0);
					break;
				default:
					break;
			}

		}
		catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	private void recvSingForward(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("收到吟唱转发指令：" + GameProtocol.SC_SING_FORWARD);

		int size = dis.readByte();
		GameActor actor;
		for (int i = 0; i < size; i++) {
			int type = dis.readByte();
			long id = dis.readLong();
			int singTime = dis.readByte();
			int singActionId = dis.readByte();
			int singEffectId = dis.readByte();
			int singSoundId = dis.readByte();
			actor = getGameActorByID(type, id);
			if (actor == m_controlledActor)
				continue;
			if (actor != null) {
				if (singEffectId != -1) {
					addEffect(singEffectId, actor.m_posX, actor.m_posY,
							actor.m_posX, actor.m_posY, singTime * 1000
									/ m_sceneHandler.getFrameInterval(),
							GameEffect.checkFlipX(actor));
				}
				if (singActionId != -1) {
					actor.setAction(singActionId
							* GameActorConstants.DIRECT_NUM + actor.m_direct,
							0, 0, true, true);
				}
			}
		}
	}

	public void recvSingInterrupt(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("收到吟唱中断指令：" + GameProtocol.SC_SING_INTERRUPT);
		int type = dis.readByte();
		long id = dis.readLong();
		GameActor actor = getGameActorByID(type, id);
		if (actor != null) {
			if (actor != m_controlledActor) {
				actor.stay(actor.m_direct);
				if (actor.m_castSrcEffect != null) {
					actor.m_castSrcEffect.deactivate();
					actor.m_castSrcEffect = null;
				}
			}
			else {
				m_controlledActor.stopCasting();
				m_controlledActor.stopCastingDescription();
				if (m_controlledActor.m_curCombatSkill != null) {
					m_controlledActor.m_curCombatSkill.deactive();
					m_controlledActor.m_curCombatSkill = null;
				}
				m_controlledActor.stay(m_controlledActor.m_direct);
			}
		}
	}

	/**
	 * 施法转发
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvCastSkillForward(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("收到施法转发指令：" + GameProtocol.SC_CAST_SKILL_FORWORD);

		int size = dis.readByte();

		for (int i = 0; i < size; i++) {
			int casterType = dis.readByte();
			long casterId = dis.readLong();
			GameActor actor = (GameActor) getGameActorByID(casterType, casterId);
			RoleCombatSkill skill = new RoleCombatSkill();
			skill.m_type = dis.readByte();
			skill.m_targetType = dis.readByte();
			skill.m_castingTime = dis.readByte();
			skill.m_castSrcActionId = dis.readByte();
			skill.m_castSrcEffectId = dis.readByte();
			skill.m_castSrcSoundId = dis.readByte();
			skill.m_castTgtEffectId = dis.readByte();
			skill.m_castTgtSoundId = dis.readByte();
			skill.m_castProcEffectId = dis.readByte();
			skill.m_castProcSoundId = dis.readByte();
			skill.m_procStartX = dis.readShort();
			skill.m_procStartY = dis.readShort();
			skill.m_procEndX = dis.readShort();
			skill.m_procEndY = dis.readShort();
			skill.m_castSpecEffectId = dis.readByte();
			skill.m_castSpecSoundId = dis.readByte();

			int tgtSize = dis.readByte();
			SkillResult[] tgtResult = new SkillResult[tgtSize];

			for (int ii = 0; ii < tgtSize; ii++) {
				tgtResult[ii] = new SkillResult();
				tgtResult[ii].m_tgtType = dis.readByte();
				tgtResult[ii].m_tgtId = dis.readLong();
				tgtResult[ii].m_tgtValue = dis.readInt();
				tgtResult[ii].m_tgtResult = dis.readByte();
				tgtResult[ii].m_tgtCurHp = dis.readInt();
			}
			try {
				if (actor == m_controlledActor) {
					Tools.debugPrintln(actor.m_name + " 正在施法技能！！");
					// 设置施法结果
					if (skill.m_type == SkillConstants.瞬发
							|| skill.m_type == SkillConstants.绝技) {
						m_controlledActor.m_curCombatSkill
								.setSkillResult(tgtResult);
						m_controlledActor.m_curCombatSkill
								.setProcEffectPosition(skill.m_procStartX,
										skill.m_procStartY, skill.m_procEndX,
										skill.m_procEndY);
					}
					else if (skill.m_type == SkillConstants.吟唱) {
						// 结束读条
						if (m_controlledActor.m_isCasting) {
							m_controlledActor.m_isCasting = false;
							m_controlledActor.stopCasting();
							m_controlledActor.stopCastingDescription();
						}

						actor.m_curCombatSkill.setSkillResult(tgtResult);
						actor.m_curCombatSkill.setProcEffectPosition(
								skill.m_procStartX, skill.m_procStartY,
								skill.m_procEndX, skill.m_procEndY);
						// 设置成施法状态
						actor.m_curCombatSkill.setToStep(SkillConstants.阶段_施法);
					}

					// actor.m_curCombatSkill.setToStep(SkillConstants.阶段_目标);
					// if (actor.m_curCombatSkill.m_castProcEffectId != -1) {
					// actor.m_curCombatSkill.setToStep(SkillConstants.阶段_过程);
					// }
					// else {
					// actor.m_curCombatSkill.setToStep(SkillConstants.阶段_目标);
					// }

				}
				else {
					if (actor == null)
						continue;
					// 如果当前技能动画未结束，则先清除当前技能
					if (actor.m_curCombatSkill != null) {
						actor.m_curCombatSkill.deactive();
						actor.m_curCombatSkill = null;
					}
					// 设置施法者以及施法结果
					skill.setCaster(actor);
					skill.setSkillResult(tgtResult);
					actor.m_curCombatSkill = skill;
					actor.m_curCombatSkill.active(this, SkillConstants.阶段_施法);
					// 设置面向
					if (tgtResult.length > 0) {
						GameActor target = getGameActorByID(
								tgtResult[0].m_tgtType, tgtResult[0].m_tgtId);
						if (target != null) {
							actor.changeDirectToTarget(target);
							skill.setTarget(target);
						}
						else {
							skill.setTarget(actor);
						}
					}
				}
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}
	}

	/**
	 * 更新buffer信息
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvBufferUpdate(DataInputStream dis) throws IOException
	{
		int type = dis.readByte();
		long id = dis.readLong();
		Tools.debugPrintln("更新buffer：" + GameProtocol.SC_BUFFER_UPDATE
				+ "-- actor id :" + id);
		GameActor actor = (GameActor) getGameActorByID(type, id);
		if (actor != null) {
			int num = dis.readByte();
			for (int i = 0; i < num; i++) {
				byte aord = dis.readByte(); // 添加或删除
				byte bufType = dis.readByte();
				long bufId = dis.readLong();
				// 删除
				if (aord == 0) {
					if (bufType == 0) {// 增益
						actor.removeBuf(bufId);
					}
					else {// 减益
						actor.removeDeBuf(bufId);
					}
					Tools.debugPrintln("删除buffer：" + bufType + " : " + bufId);
				}
				// 添加
				else {
					short iconId = dis.readShort();
					int duration = dis.readInt();
					if (bufType == 0) {// 增益
						actor.addBuf(bufId, iconId, duration);
					}
					else {// 减益
						actor.addDebuf(bufId, iconId, duration);
					}
					Tools.debugPrintln("添加buffer：" + bufType + " : " + bufId
							+ ", 持续时间：" + duration);
				}
			}
			if (id == m_controlledActor.m_gameId) {
				if (UIWindows.getMain() != null) {
					UIWindows.getMain().updateMyBuff();
				}
			}
			else if (m_controlledActor.m_targetActor != null
					&& m_controlledActor.m_targetActor.m_gameId == id) {
				if (UIWindows.getMain() != null) {
					UIWindows.getMain().updateTargetBuff();
				}
			}
		}
	}

	/**
	 * 怒气已满，激活绝技
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvSpecialSkillActive(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("怒气已满，激活绝技！ 接收到指令："
				+ GameProtocol.SC_SPECIALSKILL_ACTIVE);
		// 0:关闭 其它：激活
		boolean active = dis.readByte() == 0 ? false : true;
		if (active) {
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().bigSkill(Integer.MAX_VALUE);
			}
		}
		else {
			if (UIWindows.getMain() != null) {
				UIWindows.getMain().resetDazhao();
			}
		}
	}

	// ////////////////////////////////////////////////////////////////
	// // 伤害数字相关
	public CopyOnWriteArrayList<SkillResult> m_skillResultShow_list = new CopyOnWriteArrayList<SkillResult>();

	/**
	 * 根据类型和id移除Actor
	 *
	 * @param type
	 * @param id
	 */
	public GameActor removeGameActorById(int type, long id)
	{
		GameActor actor = null;
		switch (type) {
			case GameActorConstants.ACTOR_TYPE_ROLE:
			case GameActorConstants.ACTOR_TYPE_NPC:
			case GameActorConstants.ACTOR_TYPE_MONSTER:
			case GameActorConstants.ACTOR_TYPE_ITEM:
			case GameActorConstants.ACTOR_TYPE_GATHERING:
			case GameActorConstants.ACTOR_TYPE_PET:
				actor = removeGameActorByID(id);
				break;
			case GameActorConstants.ACTOR_TYPE_GATE:
			case GameActorConstants.ACTOR_TYPE_MAPPOINT:
			case GameActorConstants.ACTOR_TYPE_RELIVE:
				actor = deactivateNPCByID(id);
				break;
			default:
				break;
		}
		if (m_controlledActor != null) {
			if (actor == m_controlledActor.m_targetActor) {
				setTargetActor(null);
			}
		}
		return actor;
	}

	/**
	 * deactive指定id的NPC
	 *
	 * @param id
	 */
	public Npc deactivateNPCByID(long id)
	{
		GameActor actor = m_dynamicActors.get(id);
		if (actor != null && actor instanceof Npc) {
			actor.deactivate();
			return (Npc) actor;
		}
		return null;
	}

	/**
	 * 根据ID获得NPC
	 *
	 * @param id
	 * @return
	 */
	public Npc getNPCByID(long id)
	{
		GameActor actor = m_dynamicActors.get(id);
		if (actor != null && actor instanceof Npc)
			return (Npc) actor;
		return null;
	}

	// /////////////////////////////////////////////////////////////
	// // 目标相关
	public ArrayList m_targetFriendList = new ArrayList(); // 已方目标列表
	public ArrayList m_targetEnemyList = new ArrayList(); // 敌方目标列表
	public static int TARGET_RANGE = 90; // 选择范围 法师145, 剑士90, 刀客90

	/**
	 * 设置targetActor
	 *
	 * @param actor
	 */
	public void setTargetActor(GameActor actor)
	{
		m_controlledActor.m_targetActor = actor;
		m_controlledActor.clearAutoAttack();
		if (UIWindows.getMain() != null)
			UIWindows.getMain().updateTargetHead();
		if (actor == null) {
			// Tools.debugPrintln("清空目标!");
			m_targetFriendList.clear();
			m_targetEnemyList.clear();
		}
		// UIMain.updateTarget();
	}

	/**
	 * 根据ID是否是玩家自己
	 *
	 * @param long gameId
	 * @return boolean
	 * */
	public boolean containRole(long gameId)
	{
		if (DWGameManager.getInstance().m_role.m_gameId == gameId) {
			return true;
		}
		return false;
	}

	CopyOnWriteArrayList<GameActor> m_selectA = new CopyOnWriteArrayList<GameActor>();// 单向交互类的NPC（采集物）
	CopyOnWriteArrayList<GameActor> m_selectB = new CopyOnWriteArrayList<GameActor>();// 玩家可进行交互的NPC（一般NPC）
	CopyOnWriteArrayList<GameActor> m_selectC = new CopyOnWriteArrayList<GameActor>();// 除了自己以外的敌对势力玩家
	CopyOnWriteArrayList<GameActor> m_selectD = new CopyOnWriteArrayList<GameActor>();// 怪物NPC
	CopyOnWriteArrayList<GameActor> m_selectE = new CopyOnWriteArrayList<GameActor>();// 与自己同一势力的其他玩家
	CopyOnWriteArrayList<GameActor> m_selectF = new CopyOnWriteArrayList<GameActor>();// 玩家自己

	/** 清理优先级缓存列表 */
	public void releaseSelect()
	{
		m_selectA.clear();
		m_selectB.clear();
		m_selectC.clear();
		m_selectD.clear();
		m_selectE.clear();
		m_selectF.clear();
	}

	/**
	 * 是否点击到NPC
	 *
	 * @param point
	 * @return
	 */
	public GameActor isClickNpc(PointF point)
	{
		Object[] actors = m_drawList.toArray();
		int drawsize = actors.length;
		for (int i = 0; i < drawsize; i++) {
			Actor actor = (Actor) actors[i];
			GameActor ga;
			if (actor instanceof GameActor) {
				ga = (GameActor) actor;
			}
			else {
				continue;
			}
			if (ga.m_type == GameActorConstants.ACTOR_TYPE_NPC
					|| ga.m_type == GameActorConstants.ACTOR_TYPE_GATHERING
					|| ga.m_type == GameActorConstants.ACTOR_TYPE_ROLE
					|| ga.m_type == GameActorConstants.ACTOR_TYPE_MONSTER) {
				int x1 = ga.m_activeBox[0] + ga.m_posX;
				int y1 = ga.m_activeBox[1] + ga.m_posY;
				int x2 = ga.m_activeBox[2] + ga.m_posX;
				int y2 = ga.m_activeBox[3] + ga.m_posY;
				boolean isIn = Tools.pointInRectangle(point.x, point.y, x1, y1,
						x2, y2);
				if (isIn) {
					switch (ga.m_type) {
						case GameActorConstants.ACTOR_TYPE_GATHERING:
							m_selectA.add(ga);
							break;
						case GameActorConstants.ACTOR_TYPE_NPC:
							m_selectB.add(ga);
							break;
						case GameActorConstants.ACTOR_TYPE_ROLE:
							Role role = (Role) ga;
							if (role.m_faction != m_controlledActor.m_faction) {
								if (role.isOtherSellStatus()) {
									m_selectB.add(ga);
								}
								else {
									m_selectC.add(ga);
								}
							}
							else if (role.m_gameId == m_controlledActor.m_gameId) {
								if (role.isSellStatus()) {
									m_selectA.add(ga);
								}
								else {
									m_selectF.add(ga);
								}
							}
							else {
								if (role.isOtherSellStatus()) {
									m_selectB.add(ga);
								}
								else {
									m_selectE.add(ga);
								}
							}
							break;
						case GameActorConstants.ACTOR_TYPE_MONSTER:
							m_selectD.add(ga);
							break;
						default:
							continue;
					}
				}
			}
		}
		return getSelectActor();
	}

	public GameActor getSelectActor()
	{
		GameActor actor = null;
		boolean flag = m_controlledActor.m_targetActor == null ? true : false;
		boolean isTargetActor = false;
		Tools.debugPrintln("是否已经有了目标=" + flag);
		CopyOnWriteArrayList<GameActor> list = null;
		if (m_selectA.size() > 0) {
			list = m_selectA;
			Tools.debugPrintln("选择的目标数目A=" + list.size());
		}
		else if (m_selectB.size() > 0) {
			list = m_selectB;
			Tools.debugPrintln("选择的目标数目B=" + list.size());
		}
		else if (m_selectC.size() > 0) {
			list = m_selectC;
			Tools.debugPrintln("选择的目标数目C=" + list.size());
		}
		else if (m_selectD.size() > 0) {
			list = m_selectD;
			Tools.debugPrintln("选择的目标数目D=" + list.size());
		}
		else if (m_selectE.size() > 0) {
			list = m_selectE;
			Tools.debugPrintln("选择的目标数目E=" + list.size());
		}
		else if (m_selectF.size() > 0) {
			list = m_selectF;
			Tools.debugPrintln("选择的目标数目F=" + list.size());
		}
		if (list != null) {
			for (GameActor object : list) {
				if (actor != null) {// 当有对象选中后返回
					break;
				}
				if (!flag) {// 如果玩家当前有目标
					Tools.debugPrintln("列表=" + object.m_gameId + ";当前="
							+ m_controlledActor.m_targetActor.m_gameId);
					if (object.m_gameId != m_controlledActor.m_targetActor.m_gameId) {// 只有与当前已有目标不同才更改
						actor = object;
					}
					else {// 重复点到自己当前目标
						isTargetActor = true;
					}
				}
				else {
					actor = object;
				}
			}
		}
		else {
			Tools.debugPrintln("选择的目标时空的》》》》》》》》》》》》");
		}
		// 当前已经有目标并且除了还是当前选择外没有其他人，还选择当前目标
		if (!flag && actor == null && isTargetActor) {
			actor = m_controlledActor.m_targetActor;
		}
		releaseSelect();// 释放掉分级缓存
		return actor;
	}

	public static void recvSysInfo(DataInputStream dis)
	{
		try {
			String text = dis.readUTF();
			if (text.equals("")) {
				return;
			}
			final DWMessageBox mb = new DWMessageBox("提示", text);
			mb.addListener(new DWListener() {
				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					DWControlsManager.getInstance().removeControl(mb);
				}
			});
			DWControlsManager.getInstance().addControl(mb);
		}
		catch (IOException ie) {

		}

	}

	/**
	 * 确认提示
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvConfirmationPrompt(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("接收传送请求指令" + GameProtocol.SC_CONFIRMATION_PROMPT);
		String msg = dis.readUTF();
		final int order = dis.readInt();
		final String key = dis.readUTF();
		final DWMessageBox mb = new DWMessageBox("提示", msg);

		mb.addListener(new DWListener() {

			public void OnDoubleClick()
			{

			}

			public void OnClick()
			{
				if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
					DWGameManager.getInstance().getSendMessage()
							.sendFunction(order, key);
					DWControlsManager.getInstance().removeControl(mb);
				}
				else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
					DWControlsManager.getInstance().removeControl(mb);
				}
			}
		});
		DWControlsManager.getInstance().addControl(mb);
	}

	public class SceneHandler extends AbstractGameHandler
	{
		public byte m_state = 0;
		public static final byte STATE_RUN = 0;
		public static final byte STATE_WAIT = 1;
		public static final byte STATE_RETRY = 2;
		public Scene m_scene;

		public SceneHandler(Scene scene)
		{
			m_scene = scene;
			// init();
		}

		private DWConnectionCreator m_connectionCreator;

		public void openConnection()
		{
			if (m_connectionCreator == null
					&& (DWGameManager.getInstance().getConnection() == null || !DWGameManager.getInstance()
							.getConnection()
							.isAlive())) {
				m_connectionCreator = new DWConnectionCreator();
				new Thread(m_connectionCreator).start();
			}
		}

		public void logic()
		{
			switch (m_state) {
				case STATE_WAIT:
					if (m_connectionCreator != null) {
						if (m_connectionCreator.getState() == DWConnectionCreator.SUCCESS) {
							DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_默认);
							DWGameManager.getInstance().getSendMessage().sendUserServerList();
							DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_默认);
							DWGameManager.getInstance().getSendMessage().sendUserReauth(
									DWGameManager.getInstance().m_rolename, Login.m_server_session);
							m_state = STATE_RETRY;
							Tools.debugPrintln("STATE_RETRY STATE_RETRY STATE_RETRY STATE_RETRY");
							m_connectionCreator = null;
						}
						else if (m_connectionCreator.getState() == DWConnectionCreator.FAILED) {
							DWGameManager.dealForConnectionException("连接失败", "无法连接到服务器,请检查网络设置以及状态!", "重试", "退出游戏");
							m_connectionCreator = null;
						}
						else if (m_connectionCreator.getLiveTime() > DWConnectionCreator.TIME_OUT) {
							DWGameManager.dealForConnectionException("连接超时", "连接到服务器超时,请检查网络设置以及状态!", "重试", "退出游戏");
							m_connectionCreator = null;
						}
					}
					break;
				case STATE_RETRY:
					break;
			}
			updateLogic();
			updateCamera();
			updateActorList();
			DWControlsManager.getInstance().logic();
			UIWindows.getInstance().logic();
			updataParticle();
			updataParticleList();
			updatePromptUpgradeAnim();
			updateMessage();
		}

		/**
		 * 接收用户中心第一次认证
		 *
		 * @param type
		 * @param body
		 */
		private void recvUserAuthMessage(DataInputStream dis)
				throws IOException
		{

			DWGameManager.getInstance().getSendMessage()
					.unlockNetwork(GameMessage.锁_默认);
			byte type = dis.readByte();// 1快速注册 其他都是默认
			byte state = dis.readByte();
			DWGameManager.getInstance().m_rolename = dis.readUTF(); // 账号名
			Tools.debugPrintln("type=" + type + ";state = " + state);
			switch (state) {
				case 1:
					DWGameManager.getInstance().getSendMessage().sendUserDisconnectAnother();
					break;
				case 2:
					long roleID = m_controlledActor.m_gameId;
					Tools.debugPrintln("roleID =" + roleID);
					if (roleID != 0) {
						Loading.s_progress = 0;
						DWGameManager.getInstance().getSendMessage()
								.sendUserSelectRole(roleID);
					}
					break;
				default:
					DWGameManager.getInstance().dealForConnectionCreateFaile();
					break;
			}
		}

		/**
		 * 获得服务器列表 306
		 *
		 * @param dis
		 * @throws IOException
		 */
		public void recvServerListMessage(DataInputStream dis) throws IOException
		{
			Login.m_server_session = dis.readLong();// 对话标识
			byte serverAmount = dis.readByte();// 服务器数量
			Tools.debugPrintln("对话标识 : " + Login.m_server_session);
			Tools.debugPrintln("服务器数量 : " + serverAmount);
		}

		/**
		 * 接收选择人物返回信息
		 *
		 * @param type
		 * @param body
		 */
		private void recvSelectRoleMessage(DataInputStream dis) throws IOException
		{
			DWGameManager.getInstance().getSendMessage()
					.unlockNetwork(GameMessage.锁_默认);
			Tools.debugPrintln("选择人物返回信息!");
			byte state = dis.readByte();// 状态 0失败,1成功
			Tools.debugPrintln("状态 : " + state);
			if (state == 1) {
				long id = dis.readLong();// 角色id
				// if (mWorldList != null && mWorldList.size() != 0) {
				// Function func = (Function) mWorldList.get(mRoleWorldSelect);
				DWGameManager.getInstance().getSendMessage().sendUserSelectWorld(0);
				// }
			}
			else {

			}
		}

		/**
		 * 读取进入世界
		 *
		 * @param dis
		 * @throws IOException
		 */
		private void recvSelectWorldMessage(DataInputStream dis) throws IOException
		{
			byte state = dis.readByte();// 状态 0失败,1成功
			if (state == 1) {
				DWGameManager.getInstance().getSendMessage()
						.unlockNetwork(GameMessage.锁_默认);
				DWGameManager.getInstance().m_role = new Role(
						DWGameManager.getInstance().m_resourceDynamic);
				DWGameManager.getInstance().m_role.m_gameId = dis.readLong();// 角色ID
				Tools.debugPrintln("角色ID : "
						+ DWGameManager.getInstance().m_role.m_gameId);
				DWControlsManager.getInstance().removeAllControl();
				Loading loading = new Loading();
				DWGameManager.getInstance().setGameHandler(loading);
				DWGameManager.getInstance().setGameState(DWGameManager.GS_LOADING);
				Tools.debugPrintln("游戏主状态："
						+ DWGameManager.getInstance().getGameState());
			}
			else {
				DWGameManager.getInstance().addSystemInfo(
						DWGameManager.SYSTEM_INFO_TYPE_B, "进入世界失败!");
			}
			//注释掉。。
//			ChannelOperation.enterGame();
		}

		public boolean recvMessage(int type, DataInputStream dis)
				throws Exception
		{

			int order = BaseConnection.s_perseOrderID;

			try {
				DWGameManager.getInstance().getSendMessage()
						.unlockNetwork(GameMessage.锁_默认);
				switch (order) {
				//时装外显
					case GameProtocol.SC_SHIZHUANG_DISPLAY:
						UIWindows.getInstance().m_bag.recvOpenshizhuang_display(dis);
						break;
					case GameProtocol.SC_SHIZHUANG_STATE:
						UIWindows.getInstance().m_bag.recvOpenshizhuang_response(dis);
						break;
					//成就奖励
					case GameProtocol.SC_ACHIEVEMENT_ALL:
						UIWindows.getInstance().m_achie.recvAchieve(dis);
						break;
					case GameProtocol.SC_ACHIEVEMENT_GET:
						UIWindows.getInstance().m_achie.recvLingqu(dis);
						break;
					case GameProtocol.SC_ACHIEVEMENT_STATE:
						UIWindows.getInstance().m_achie.recvAchieveId(dis);
						break;
					//断网重连
					case GameProtocol.SC_USER_AUTH:
					case GameProtocol.CS_USER_REAUTH:
						recvUserAuthMessage(dis);
						break;
					case GameProtocol.SC_USER_SELECT_WORLD:
						recvSelectWorldMessage(dis);
						break;
					case GameProtocol.SC_USER_SELECT_ROLE:
						recvSelectRoleMessage(dis);
						break;
					case GameProtocol.SC_USER_SERVER_LIST:
						recvServerListMessage(dis);
						break;
					// 摆摊
					case GameProtocol.SC_BAITAN_SELLBUY:
						UIWindows.getInstance().m_baitan.recvBaitanbuy(dis);
						break;
					case GameProtocol.SC_BAITAN_STALLEND:
						UIWindows.getInstance().m_baitan.recvBaitansellend(dis);
						break;
					case GameProtocol.SC_BAITAN_CHAKAN:
						UIWindows.getInstance().m_baitan.recvBaitanChakan(dis);
						break;
					case GameProtocol.SC_BAITAN_FASONG:
						UIWindows.getInstance().m_baitan.recvBaitanFasong(dis);
						break;
					case GameProtocol.SC_BAITAN_RESULT:
						recvBaitanResult(dis);
						break;
					//乐透
					case GameProtocol.SC_OpenLOTTERY:
						UIWindows.getInstance().m_letou.recvOpenLOTTERY(dis);
						break;
					case GameProtocol.SC_REQUESTLOTTERY:
						UIWindows.getInstance().m_letou.recvREQUESTLOTTERY(dis);
						break;
					case GameProtocol.SC_GETLOTTERYPRIZE:
						UIWindows.getInstance().m_letou.recvGETLOTTERYPRIZE(dis);
						break;
					case GameProtocol.SC_WANTED_LIST:

						UIWindows.getInstance().m_npctongji.recvSocialTongji(dis);

						break;
					case GameProtocol.SC_WANTED_DEBUFF:

						UIWindows.getInstance().m_npctongji.recvSocialTongjibuff(dis);

						break;
					case GameProtocol.SC_ANSWER_Confirmation1:
						DWGameManager.getInstance().getSendMessage()
								.unlockNetwork(GameMessage.锁_答题);
						UIWindows.getInstance().m_answer.drawtwoconfirmed(dis);
						break;
					case GameProtocol.SC_ANSWER_ING:
						UIWindows.getInstance().m_answer.recvAnswer(dis);
						break;
					case GameProtocol.SC_MEIRI_CMD:
						UIWindows.getInstance().m_meiri.recvMeiri(dis);
						break;
					case GameProtocol.SC_HINT_A:
						Tools.debugPrintln("读取A类提示!");
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_A,
								recvReadString(dis));
						break;
					case GameProtocol.SC_HINT_B:
						Tools.debugPrintln("读取B类提示!");
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_B,
								recvReadString(dis));
						break;
					case GameProtocol.SC_HINT_C:
						Tools.debugPrintln("读取C类提示!");
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_C,
								recvReadString(dis));
						break;
					case GameProtocol.SC_HINT_D:
						Tools.debugPrintln("读取D类提示!");
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_D,
								recvReadString(dis));
						break;
					case GameProtocol.SC_HINT_E:
						Tools.debugPrintln("读取E类提示!");
						recvInfo(dis);
						break;
					case GameProtocol.SC_HINT_F:
						Tools.debugPrintln("读取F类提示!");
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_F,
								recvReadString(dis));
						break;
					case GameProtocol.SC_CONFIRMATION_PROMPT:
						recvConfirmationPrompt(dis);
						break;
					case GameProtocol.S_SYSTEM_INFO:
						Tools.debugPrintln("读取系统信息!");
						Scene.recvSysInfo(dis);
						break;
					case GameProtocol.SC_UPDATE_PROPERTIES:
						recvUpdateRoleProperties(dis);
						break;
					case GameProtocol.CS_SCENE_UPDATE:
						// recvUpdateMessage(dis);
						break;
					case GameProtocol.SC_SCENE_UPGRADE:
						Tools.debugPrintln("读取升级信息");
						recvSceneUpgrade(dis);
						break;
					case GameProtocol.SC_SCENE_POSITION_REVISE:
						recvScenePostionRevise(dis);
						break;
					case GameProtocol.SC_SCENE_ADD_ACTOR:
						recvAddActor2(dis);
						break;
					case GameProtocol.SC_SCENE_REMOVE_ACTOR:
						recvRemoveActor(dis);
						break;
					case GameProtocol.SC_SCENE_UPDATE_ACTOR_POSITION:
						recvUpdateActorPosition2(dis);
						break;
					case GameProtocol.SC_SCENE_UPDATE_ACTOR_DATA:
						recvUpdateActorData2(dis);
						break;
					case GameProtocol.SC_SCENE_UPDATE_ACTOR_FIGURE:
						recvUpdateActorFigure2(dis);
						break;
					case GameProtocol.SC_SCENE_UPDATE_ACTOR_STATUS:
						recvUpdateActorStatus(dis);
						break;
					case GameProtocol.SC_SCENE_UPDATE_ACTOR_ACTION:
						recvUpdateActorAction(dis);
						break;
					case GameProtocol.SC_SCENE_UPDATE_ACTOR_FLAG:
						recvUpdateActorFlag(dis);
						break;
					case GameProtocol.SC_BUFFER_UPDATE:
						recvBufferUpdate(dis);
						break;
					case GameProtocol.CS_CAST_SKILL:
						recvCastSkill(dis);
						break;
					case GameProtocol.SC_CAST_SKILL_FORWORD:
						recvCastSkillForward(dis);
						break;
					case GameProtocol.SC_SING_FORWARD:
						recvSingForward(dis);
						break;
					case GameProtocol.SC_SING_INTERRUPT:
						recvSingInterrupt(dis);
						break;
					case GameProtocol.SC_NPC_SKILL_FORWARD:
						// recvNPCSkillForward(dis);
						break;
					case GameProtocol.SC_LEARN_COMBAT_SKILL:
						recvLearnCombatSkill(dis);
						break;
					case GameProtocol.SC_ACTIVE_COMBAT_SKILL:
						recvActiveCombatSkill(dis);
						break;
					case GameProtocol.SC_SPECIALSKILL_ACTIVE:
						recvSpecialSkillActive(dis);
						break;
					case GameProtocol.SC_SCENE_CONFIRMATION:
						recvSceneConfirmation(dis);
						break;
					case GameProtocol.SC_OPEN_RESET_SKILL:
						Tools.debugPrintln("recv  打开重置技能界面");
						UIWindows.getInstance().m_skill.recvOpenReste(dis);
						break;
					case GameProtocol.SC_RESET_SKILL_APPLICATION:
						Tools.debugPrintln("recv  重置技能结果");
						UIWindows.getInstance().m_skill.recvResetResult(dis);
						break;

					/******************* 任务 ******************/
					case GameProtocol.CS_TASK_ROLE_LIST:
						Tools.debugPrintln("recv  剧情任务列表	");
						UIWindows.getInstance().m_renwu.recvRoleTaskList(dis);
						break;
					case GameProtocol.SC_TASK_ROLE_VIEW:
						Tools.debugPrintln("recv  任务列表的详细信息	");
						UIWindows.getInstance().m_renwu.recvTaskViewRole(dis);
						break;
					case GameProtocol.SC_TASK_NPC_VIEW:
						Tools.debugPrintln("recv  NPC任务列表的详细信息");
						UIWindows.getInstance().m_renwu.recvTaskViewNPC(dis);
						break;
					case GameProtocol.CS_TASK_BEGIN:
						Tools.debugPrintln("recv  接受任务");
						UIWindows.getInstance().m_renwu.recvTaskBegin(dis);
						break;
					case GameProtocol.CS_TASK_ABORT:
						Tools.debugPrintln("recv  放弃任务");
						UIWindows.getInstance().m_renwu.recvTaskAbort(dis);
						break;
					case GameProtocol.CS_TASK_FINISH:
						Tools.debugPrintln("recv  完成任务");
						UIWindows.getInstance().m_renwu.recvTaskFinish(dis);
						break;
					case GameProtocol.SC_TASK_UPDATE_STATUS:
						Tools.debugPrintln("recv 任务状态更新。。。");
						UIWindows.getInstance().m_renwu.recvTaskUpdateStatus(dis);
						break;
					case GameProtocol.CS_TASK_ACCEPTABLYTASKLIST:
						Tools.debugPrintln("recv 可接任务列表。。。");
						UIWindows.getInstance().m_renwu
								.recvRoleacceptablyTaskList(dis);
						break;
					// 洞府
					case GameProtocol.SC_DONGFU_INTO_DONGFU:
						Tools.debugPrintln("recv进入摇钱树");
						UIWindows.getInstance().m_getMoney.recvYaoQianShu(dis);
						break;
					case GameProtocol.SC_DONGFU_REAP_DONGFU:
						Tools.debugPrintln("recv摇钱树收获");
						UIWindows.getInstance().m_getMoney.recvReapYQS(dis);
						break;
					case GameProtocol.SC_DONGFU_WATERING:
						Tools.debugPrintln("recv 摇钱树浇灌");
						UIWindows.getInstance().m_getMoney.recvWarteing(dis);
						break;
					case GameProtocol.SC_YQS_FRIEND_LIST:
						Tools.debugPrintln("recv 摇钱树浇灌");
						UIWindows.getInstance().m_getMoney.recvYQSFriendList(dis);
						break;
					case GameProtocol.SC_SOCIAL_LIST:
						Tools.debugPrintln("读取社交列表!");
						UIWindows.getInstance().m_social.recvSocialList(dis);
						break;
					case GameProtocol.SC_SOCIAL_ID_ADD:
						Tools.debugPrintln("读取社交列表添加玩家!");
						UIWindows.getInstance().m_social.recvSocialAdd(dis);
						break;
					case GameProtocol.SC_SOCIAL_DELETE:
						Tools.debugPrintln("读取社交列表删除玩家!");
						UIWindows.getInstance().m_social.recvSocialDelete(dis);
						break;
					case GameProtocol.SC_SOCIAL_CONFIRMATION:
						Tools.debugPrintln("读取添加好友确认信息!");
						UIWindows.getInstance().m_social
								.recvSocialConfirmation(dis);
						break;
					// 仇敌
					case GameProtocol.SC_SOCIAL_ENEMY_ENEMYLIST:
						Tools.debugPrintln("recv仇敌信息");
						UIWindows.getInstance().m_social.recvSocialEnemyList(dis);
						break;
					case GameProtocol.SC_SOCIAL_ENEMY_DELETE:
						Tools.debugPrintln("recv仇敌解除");
						UIWindows.getInstance().m_social.recvSocialEnemyDelete(dis);
						break;
					case GameProtocol.SC_SOCIAL_ENEMY_ENEMYINFO:
						Tools.debugPrintln("recv仇敌详细信息");
						UIWindows.getInstance().m_social.recvSocialEnemyInfo(dis);
						break;
					case GameProtocol.SC_SOCIAL_ENEMY_LOCK:
						Tools.debugPrintln("recv仇敌锁定");
						UIWindows.getInstance().m_social.recvSocialEnemyLock(dis);
						break;
					case GameProtocol.SC_SOCIAL_ENEMY_QUERY_POSITION:
						Tools.debugPrintln("recv仇敌具体位置");
						UIWindows.getInstance().m_social
								.recvSocialEnemyPosition(dis);
						break;
					case GameProtocol.SC_SOCIAL_ENEMY_WANTED_POSTER:
						Tools.debugPrintln("recv仇敌发布返回通缉令结果");
						UIWindows.getInstance().m_social.recvSocialEnemyWanted(dis);
						break;
					case GameProtocol.SC_SCENE_NPC_STATUS:
						recvSceneNPCStatus(dis); // 同屏更新npc头上任务状态
						break;
					case GameProtocol.SC_NPC_LIST:
						Tools.debugPrintln("recv 任务列表");
						recvNPCList(dis);
						break;
					case GameProtocol.SC_NPC_INTERACT:
						Tools.debugPrintln("读取NPC互动任务!");
						recvNPCInteract(dis);
						break;
					case GameProtocol.SC_NPC_INTERACT_BREAK:
						recvNPCInteractBreak(dis);
						break;
					case GameProtocol.操作菜单_使用:
						Tools.debugPrintln("recv 道具使用成功");
						DWGameManager.getInstance().m_role
								.recvItemConsumeUsedOK(dis);
						break;
					case GameProtocol.SC_EXCHANGECELL_COMMAND:
						Tools.debugPrintln("recv 交换格子信息");
						DWGameManager.getInstance().m_role
								.recvExchangeCellCommand(dis);
						break;
					case GameProtocol.SC_CHNAGE_CELL_COMMAND:
						Tools.debugPrintln("recv 改变格子道具信息");
						DWGameManager.getInstance().m_role
								.recvChangeCellCommand(dis);
						break;
					case GameProtocol.SC_ADD_ITEM_COMMAND:
						Tools.debugPrintln("recv 添加道具信息");
						DWGameManager.getInstance().m_role.recvAddItemCommand(dis);
						break;
					case GameProtocol.SC_CHANGE_EQUIP_INFOS_COMMAND:
						Tools.debugPrintln("recv 改变装备属性信息");
						DWGameManager.getInstance().m_role
								.recvChangeEquipInfosCommand(dis);
						break;
					case GameProtocol.SC_CHANGE_EQUIP_STRENGTHEN_COMMAND:
						Tools.debugPrintln("recv 改变装备强化信息");
						DWGameManager.getInstance().m_role
								.recvChangeEquipStrengthenCommand(dis);
						break;
					case GameProtocol.SC_CHANGE_EQUIP_SET_COMMAND:
						Tools.debugPrintln("recv 改变装备镶嵌信息");
						DWGameManager.getInstance().m_role
								.recvChangeEquipSetCommand(dis);
						break;
					case GameProtocol.SC_CHANGE_EQUIP_BINDING_COMMAND:
						Tools.debugPrintln("recv 改变装备绑定信息");
						DWGameManager.getInstance().m_role
								.recvChangeEquipBindingCommand(dis);
						break;
					case GameProtocol.SC_CHANGE_EQUIP_DURABLE_COMMAND:
						Tools.debugPrintln("recv 改变装备耐久信息");
						DWGameManager.getInstance().m_role
								.recvChangeEquipDurableCommand(dis);
						break;
					case GameProtocol.SC_COLUMN_COMMAND:
						Tools.debugPrintln("recv 整理背包栏");
						DWGameManager.getInstance().m_role.recvColumnCommand(dis);
						break;
					case GameProtocol.操作菜单_扩充栏:
						Tools.debugPrintln("recv 扩充格子");
						DWGameManager.getInstance().m_role
								.recvChangeColumnCellNumbers(dis);
						break;

					case GameProtocol.操作装备_强化:
						Tools.debugPrintln("recv 强化是否成成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong.recvStrengThen(dis);
						}
						break;
					case GameProtocol.SC_SET_GEM_COMMAND:
						Tools.debugPrintln("recv 镶嵌宝石是否成成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong.recvSetGem(dis);;
						}
						break;
					case GameProtocol.SC_SYNTHESIS_GEM_COMMAND:
						Tools.debugPrintln("recv 合成宝石是否成成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvSynthesisGem(dis);
						}
						break;
					case GameProtocol.SC_SEE_NEXTLEVEL_GEM:
						Tools.debugPrintln("recv 查看下一级宝石");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvSeeNextLevelGem(dis);
						}
						break;
					case GameProtocol.SC_SMELTING_EQUIP:
						Tools.debugPrintln("recv 分解装备是否成成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvSmeltingEquip(dis);
						}
						break;
					case GameProtocol.SC_SURE_TO_SMELTING:
						Tools.debugPrintln("recv 确定分解是否成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvSureToSmelting(dis);
						}
						break;
					case GameProtocol.SC_EXTRACTION_SPIRIT_NUM:
						Tools.debugPrintln("recv 抽取精魂消耗金钱数及获得精魂数");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvExtractionSpiritNum(dis);
						}
						break;
					case GameProtocol.SC_EXTRACTION_SPIRIT:
						Tools.debugPrintln("recv 抽取精魂是否成成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvExtractionSpirit(dis);
						}
						break;
					case GameProtocol.SC_DOWN_GEM:
						Tools.debugPrintln("recv 取下宝石是否成成功");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong.recvDownGem(dis);
						}
						break;
					case GameProtocol.SC_STRENGTHEN_NEXTLEVEL_VALUES:
						Tools.debugPrintln("recv 查看下级强化值");
						if (UIWindows.getInstance().m_tiangong != null) {
							UIWindows.getInstance().m_tiangong
									.recvStrengthenNextLevelValues(dis);
						}
						break;
					case GameProtocol.SC_SEE_ITEM_INFOS:
						Tools.debugPrintln("recv 查看道具详情");
						if (UIWindows.getInstance().m_bag != null) {
							UIWindows.getInstance().m_bag.recvSeeItemInfos(dis);
						}
						break;
					// / 内丹 ////
					case GameProtocol.SC_NEIDANG_OPENWIN:
						Tools.debugPrintln("recv 开启内丹界面");
						UIWindows.getInstance().m_neidan.recvNeiDanOpenWin(dis);
						break;
					case GameProtocol.SC_NEIDANG_EAT:
						Tools.debugPrintln("recv 使用内丹");
						UIWindows.getInstance().m_neidan.recvNeiDanEat(dis);
						break;

					// /家族副本
					case GameProtocol.SC_FAMILY_CARBON_COUNT:
						Tools.debugPrintln("recv 家族副本结算");
						UIWindows.getInstance().m_facarbon.recvFamilyCarbon(dis);
						break;
					case GameProtocol.SC_FAMILY_CARBON_DJS:
						Tools.debugPrintln("recv 家族副本倒计时");
						UIWindows.getInstance().m_facarbon.recvFamilyDJS(dis);
						break;
					case GameProtocol.SC_FAMILY_CARBON_DWPR:
						Tools.debugPrintln("recv 家族副本的购买");
						UIWindows.getInstance().m_facarbon.recvFamilyDepr(dis);
						break;
					case GameProtocol.SC_FAMILY_CARBON_FAIL:
						Tools.debugPrintln("recv 家族副本失败");
						UIWindows.getInstance().m_facarbon.recvFamilyFail(dis);
						break;
					case GameProtocol.SC_CHONGWU_OPEN:
						Tools.debugPrintln("recv 打开宠物界面");
						UIWindows.getInstance().m_pet.recvPetOpenWin(dis);
						break;
					case GameProtocol.SC_CHONGWU_CHUZHAN:
						Tools.debugPrintln("recv 宠物出战或收回");
						UIWindows.getInstance().m_pet.recvPetCZorSH(dis);
						break;
					case GameProtocol.SC_CHONGWU_KUOBEIBAO:
						Tools.debugPrintln("recv 宠物扩背包");
						UIWindows.getInstance().m_pet.recvPetBagNum(dis);
						break;
					case GameProtocol.SC_CHONGWU_CHANGENAME:
						Tools.debugPrintln("recv 宠物改名");
						UIWindows.getInstance().m_petMenu.recvChangeName(dis);
						break;
					case GameProtocol.SC_TIANMING_BAG:
						Tools.debugPrintln("recv 天命背包数据");
						UIWindows.getInstance().m_jiming.recvTianMingBug(dis);
						break;
					case GameProtocol.SC_TIANMING_OPEN:
						Tools.debugPrintln("recv 开启天命所需数据");
						UIWindows.getInstance().m_jiming.recvTianMingData(dis);
						break;
					case GameProtocol.SC_CLT_JTT_TIANMING:
						Tools.debugPrintln("recv 打开祭天台");
						UIWindows.getInstance().m_jiming.recvTianMingDaKai(dis);
						break;
					case GameProtocol.SC_TIANMING_MONEY:
						Tools.debugPrintln("recv 开启天命拜神花费");
						UIWindows.getInstance().m_jiming
								.recvTianMingJiBaiMoney(dis);
						break;
					case GameProtocol.SC_TIANMING_STATE:
						Tools.debugPrintln("recv 天命所有操作放回");
						UIWindows.getInstance().m_jiming.recvTianMingState(dis);
						break;
					case GameProtocol.SC_TIANMING_UNLOAD:
						Tools.debugPrintln("recv 天命卸下");
						UIWindows.getInstance().m_jiming.recvTianMingUnLoadTM(dis);
						break;
					case GameProtocol.SC_TIANMING_KUOBEIBAO:
						Tools.debugPrintln("recv 扩充天命背包");
						UIWindows.getInstance().m_jiming.recvTianMingKuoBeiBao(dis);
						break;
					case GameProtocol.SC_CLT_JB_TM_BAG:
						Tools.debugPrintln("recv 祭拜结果");
						UIWindows.getInstance().m_jiming
								.recvTianMingJiBaiJieGuo(dis);
						break;
					// /邮件
					case GameProtocol.SC_REQUEST_ROLE_MAILS:
						Tools.debugPrintln("场景中读取角色邮件");
						DWGameManager.getInstance().m_role
								.recvRequestRoleMails(dis);
						break;
					case GameProtocol.SC_REQUEST_NEW_MAILS:
						Tools.debugPrintln("recv 新邮件信息"
								+ GameProtocol.SC_REQUEST_NEW_MAILS);
						UIWindows.getInstance().m_mail.recvRequestNewMails(dis);
						break;
					case GameProtocol.SC_REQUEST_GET_ANNEX:
						Tools.debugPrintln("recv 获取附件是否成功"
								+ GameProtocol.SC_REQUEST_GET_ANNEX);
						UIWindows.getInstance().m_mail.recvGetMailAnnex(dis);
						break;
					case GameProtocol.SC_SEND_MAIL:
						Tools.debugPrintln("recv 发送邮件是否成功"
								+ GameProtocol.SC_SEND_MAIL);
						UIWindows.getInstance().m_mail.recvSendMail(dis);
						break;
					case GameProtocol.SC_HAVE_NEW_MAILS:
						Tools.debugPrintln("recv 界面显示有新邮件,邮件界面提示"
								+ GameProtocol.SC_HAVE_NEW_MAILS);
						UIWindows.getInstance().m_main.recvNewMailShow(dis);
						break;
					// 家族
					case GameProtocol.SC_FAMILY_VERIFY:
						Tools.debugPrintln("recv 验证是否可以创建家族");
						UIWindows.getInstance().m_family.recvFamilyVerify(dis);
						break;
					case GameProtocol.SC_FAMILY_CREATE:
						Tools.debugPrintln("recv 创建家族");
						UIWindows.getInstance().m_family.recvFamilyCreate(dis);
						break;
					case GameProtocol.SC_FAMILY_OWN_MESSAGE: // 查看自己家族的信息
						Tools.debugPrintln("recv 查看自己家族的信息");
						UIWindows.getInstance().m_family.recvFamilyOwnMessage(dis);
						break;
					case GameProtocol.SC_FAMILY_OTHER_MESSAGE:
						Tools.debugPrintln("recv 查看其他家族的信息");
						UIWindows.getInstance().m_family
								.recvFamilyOtherMessage(dis);// 查看其他家族信息
						break;
					case GameProtocol.SC_FAMILY_MODIFY_MANIFESTO:// 修改家族宣言
						Tools.debugPrintln("recv 修改家族宣言");
						UIWindows.getInstance().m_family
								.recvFamilyModifyManifesto(dis);
						break;
					case GameProtocol.SC_FAMILY_MODIFY_NOTICE:// 修改家族公告
						Tools.debugPrintln("recv 修改家族公告");
						UIWindows.getInstance().m_family
								.recvFamilyModifyNotice(dis);
						break;
					case GameProtocol.SC_FAMILY_UPDATE_POSITION:// 服务器更新家族职位
						Tools.debugPrintln("recv 服务器更新家族职位");
						UIWindows.getInstance().m_family
								.recvFamilyUpdatePosition(dis);
						break;
					case GameProtocol.SC_FAMILY_APPLY_ADD: // 读取申请加入家族
						Tools.debugPrintln("recv 读取申请加入家族");
						UIWindows.getInstance().m_family.recvFamilyApplyAdd(dis);
						break;
					case GameProtocol.SC_FAMILY_APPLY_LIST:// 查看家族申请列表
						Tools.debugPrintln("recv 查看家族申请列表");
						UIWindows.getInstance().m_family.recvFamilyApplyList(dis);
						break;
					case GameProtocol.SC_FAMILY_RATIFY_ADD:// 读取批准申请
						Tools.debugPrintln("recv 读取批准申请");
						UIWindows.getInstance().m_family.recvFamilyRatifyAdd(dis);
						break;
					case GameProtocol.SC_FAMILY_INVITE_ADD_NAME:// 通过名字邀请加入家族
						Tools.debugPrintln("recv 通过名字邀请加入家族");
						UIWindows.getInstance().m_family.recvFamilyInviteAdd(dis);
						break;
					case GameProtocol.SC_FAMILY_INVITEE_ADD:// 被邀请加入家族
						Tools.debugPrintln("recv 被邀请加入家族");
						UIWindows.getInstance().m_family.recvFamilyInviteeAdd(dis);
						break;
					case GameProtocol.SC_FAMILY_MEMBER_LIST:// 家族成员列表
						Tools.debugPrintln("recv 家族成员列表");
						UIWindows.getInstance().m_family.recvFamilyMemberList(dis);
						break;
					case GameProtocol.SC_FAMILY_CONFIRM_LEAVE:// 确认离开家族
						Tools.debugPrintln("recv 确认离开家族");
						UIWindows.getInstance().m_family
								.recvFamilyConfirmLeave(dis);
						break;
					case GameProtocol.SC_FAMILY_EXPEL:// 开除成员
						Tools.debugPrintln("recv 开除成员");
						UIWindows.getInstance().m_family.recvFamilyExpel(dis);
						break;
					case GameProtocol.SC_FAMILY_DISMISS:// 解散家族
						Tools.debugPrintln("recv 解散家族");
						UIWindows.getInstance().m_family.recvFamilyDismiss(dis);
						break;
					case GameProtocol.SC_FAMILY_CANCEL_DISMISS:// 取消解散家族
						UIWindows.getInstance().m_family
								.recvFamilyCancelDismiss(dis);
						Tools.debugPrintln("recv 取消解散家族");
						break;
					case GameProtocol.SC_FAMILY_SET_ELDER:// 提拔/免职长老
						Tools.debugPrintln("recv 提拔/免职长老");
						UIWindows.getInstance().m_family.recvFamilySetElder(dis);
						break;
					case GameProtocol.SC_FAMILY_DEMISE_SHEIKH:// 禅让族长
						Tools.debugPrintln("recv 禅让族长");
						UIWindows.getInstance().m_family
								.recvFamilyDemiseSheikh(dis);
						break;
					case GameProtocol.SC_FAMILY_APPLY_MERGE:// 申请合并家族
						Tools.debugPrintln("recv 申请合并家族");
						UIWindows.getInstance().m_family.recvFamilyApplyMerge(dis);
						break;
					case GameProtocol.SC_FAMILY_LUCKY_OPEN:// 开启抽奖界面
						Tools.debugPrintln("recv 开启抽奖界面");
						UIWindows.getInstance().m_family.recvFamilyLuckOpen(dis);
						break;
					case GameProtocol.SC_FAMILY_LUCKY_RESULT:// 抽奖结果获得
						Tools.debugPrintln("recv 抽奖结果获得");
						UIWindows.getInstance().m_family.recvFamilyLuckResult(dis);
						break;
					case GameProtocol.SC_FAMILY_FAMILYLIST:
						Tools.debugPrintln("recv 家族列表获得"
								+ GameProtocol.SC_FAMILY_FAMILYLIST);
						UIWindows.getInstance().m_family.recvFamilyList(dis);
						break;
					case GameProtocol.SC_FAMILY_LOOKSKILL:
						Tools.debugPrintln("recv 家族技能列表获得"
							+ GameProtocol.SC_FAMILY_LOOKSKILL);
						UIWindows.getInstance().m_family.recvFamilySkill(dis);
						break;
					case GameProtocol.SC_FAMILY_LOOKSKILLAGAIN:
						Tools.debugPrintln("recv 一次以后 家族技能列表获得"
							+ GameProtocol.SC_FAMILY_LOOKSKILLAGAIN);
						UIWindows.getInstance().m_family.recvFamilyOpenSkillAgain(dis);
						break;
					case GameProtocol.SC_FAMILY_STUDYSKILL:
						Tools.debugPrintln("recv 家族技能的学习"
							+ GameProtocol.SC_FAMILY_STUDYSKILL);
						UIWindows.getInstance().m_family.recvFamilyStudySkill(dis);
						break;
					case GameProtocol.SC_HELP_GONG_JUANXIAN:
						UIWindows.getInstance().m_family.recvFamilyJuanXian(dis);
						Tools.debugPrintln("收到指令："
								+ GameProtocol.SC_HELP_GONG_JUANXIAN);
						break;
					case GameProtocol.SC_HELP_GONG_SHUAXIN:
						UIWindows.getInstance().m_family.recvFamilyZhi(dis);
						Tools.debugPrintln("收到指令："
								+ GameProtocol.SC_HELP_GONG_SHUAXIN);
						break;

					// 组队相关
					case GameProtocol.SC_TEAM_SYNCHRO:// 队伍同屏信息
						recvTeamMSG(dis);
						break;

					case GameProtocol.SC_TEAM_SUCCEED:
						Tools.debugPrintln("recv组队是否成功");
						UIWindows.getInstance().m_social.recvTeamIsSucceed(dis);
						break;
					case GameProtocol.SC_TEAM_AGREE:
						Tools.debugPrintln("recv组队请求是否同意");
						UIWindows.getInstance().m_social.recvTeamIsAgree(dis);
						break;
					case GameProtocol.SC_TEAM_MESSAGE:
						Tools.debugPrintln("recv获得全队信息");
						UIWindows.getInstance().m_social.recvTeamInfo(dis);
						break;
					case GameProtocol.SC_TEAM_QUITTEAM:
						Tools.debugPrintln("recv退出队伍是否成功");
						UIWindows.getInstance().m_social.recvTeamRequst(dis);
						break;
					case GameProtocol.SC_TEAM_LEADERHANDLE:
						Tools.debugPrintln("recv队长操作SC");
						UIWindows.getInstance().m_social.recvTeamLeader(dis);
						break;
					case GameProtocol.SC_TEAM_TEAMAUTOCREATE:
						Tools.debugPrintln("recv自动组队");
						UIWindows.getInstance().m_social.recvTeamAutoCreate(dis);
						break;
					case GameProtocol.SC_TEAM_TEAMNEAR:
						Tools.debugPrintln("recv附近队伍");
						UIWindows.getInstance().m_social.recvTeamNearby(dis);
						break;
					case GameProtocol.SC_TEAM_APPLYJOIN:
						Tools.debugPrintln("recv加入队伍");
						UIWindows.getInstance().m_social.recvTeamApplyJoin(dis);
						break;
					case GameProtocol.SC_TEAM_TEAMLEADERCHANGE:
						Tools.debugPrintln("recv 队伍变更");
						DWGameManager.getInstance().m_role
								.recvTeamLeaderChange(dis);
						break;
					/** 切换角色 */
					case GameProtocol.S_USER_RESEL:
						UIWindows.getInstance().m_setup.recvChangeRole(dis);
						break;
					/**** 副本 ****/
					case GameProtocol.SC_GAMECARBON_FINISH:
						Tools.debugPrintln("接收副本通关提示" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonFinish(dis);
						break;
					case GameProtocol.CS_GAMECARBON_OPEN:
						Tools.debugPrintln("接收副本界面开启" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonOpen(dis);
						break;
					case GameProtocol.SC_GAMECARBON_BUY:
						Tools.debugPrintln("接收副本购买精力次数" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonBuy(dis);
						break;
					case GameProtocol.CS_GAMECARBON_CHECK:
						Tools.debugPrintln("接收副本检测" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonCheck(dis);
						break;
					case GameProtocol.CS_GAMECARBON_AUTO:
						Tools.debugPrintln("接收副本自动组队" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonAuto(dis);
						break;
					case GameProtocol.CS_GAMECARBON_UPDATE:
						Tools.debugPrintln("接收副本状态更新" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonUpdate(dis);
						break;
					case GameProtocol.CS_GAMECARBON_ADD:
						Tools.debugPrintln("接收副本增次" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonAdd(dis);
						break;
					case GameProtocol.SC_GAMECARBON_REWARD:
						Tools.debugPrintln("接收副本通关" + order + "!");
						UIWindows.getInstance().m_fuben
								.recvGameCarbonOverReward(dis);
						break;
					case GameProtocol.CS_GAMECARBON_OPEN_BOX:
						Tools.debugPrintln("接收副本通关开启某个宝箱：" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonOpenBox(dis);
						break;
					case GameProtocol.CS_GAMECARBON_REWARD_DETAILS:
						Tools.debugPrintln("接收副本详情：" + order + "!");
						UIWindows.getInstance().m_fuben
								.recvGameCarbonRewardDetails(dis);
						break;
					case GameProtocol.CS_GAMECARBON_G_VIM:
						Tools.debugPrintln("接收副本购买精力：" + order + "!");
						UIWindows.getInstance().m_fuben.recvGameCarbonGVim(dis);
						break;
					case GameProtocol.CS_SCENE_PATHFINDING:
						Tools.debugPrintln("读取世界寻路");
						recvScenePathfinding(dis);
						break;
					case GameProtocol.SC_CREAT_NPC_SHOP:
						Tools.debugPrintln("recv 打买开商店界面");
						UIWindows.getInstance().m_npcShop.recvNpcShopList(dis);
						break;
					case GameProtocol.SC_SHOP_BUY_ITEM:
						Tools.debugPrintln("recv 购买商店的道具是否成功");
						if (UIWindows.getInstance().m_npcShop != null) {
							UIWindows.getInstance().m_npcShop.recvShopBuyItem(dis);
						}
						break;
					case GameProtocol.S_NPC_SAIL_ENTER:
						Tools.debugPrintln("recv 打卖开商店界面");
						if (UIWindows.getInstance().m_npcShop != null) {
							UIWindows.getInstance().m_npcShop.recvOpenSailShop(dis);
						}
						break;
					case GameProtocol.SC_NPC_SHOP_SAIL:
						Tools.debugPrintln("recv 出售道具是否成功");
						if (UIWindows.getInstance().m_npcShop != null) {
							UIWindows.getInstance().m_npcShop.recvNpcshopSail(dis);
						}
						break;
					case GameProtocol.CS_NPC_FIX_ENTER:
						Tools.debugPrintln("recv 打开修理商店");
						if (UIWindows.getInstance().m_fix != null) {
							UIWindows.getInstance().m_fix.recvOpenFixShop(dis);
						}
						break;
					case GameProtocol.SC_NPC_FIX_EQUIPS:
						Tools.debugPrintln("recv 修理装备栏装备");
						if (UIWindows.getInstance().m_fix != null) {
							UIWindows.getInstance().m_fix.recvFixEquips(dis);
						}
						break;
					case GameProtocol.SC_NPC_FIX_ALL:
						Tools.debugPrintln("recv 修理所有装备");
						if (UIWindows.getInstance().m_fix != null) {
							UIWindows.getInstance().m_fix.recvFixAll(dis);
						}
						break;
					case GameProtocol.SC_VIP_AUTOREPAIRE_EQUIP:
						Tools.debugPrintln("recv VIP自动修理");
						if (DWGameManager.getInstance().m_role != null) {
							DWGameManager.getInstance().m_role.recvVipAutoRepairEquip(dis);
						}
						break;
					// 聊天信息
					case GameProtocol.CS_CHAT_INFOS:
						recvChatInfos(dis);
						break;
					case GameProtocol.S_CHAT_WORLD_CONFIG:
						recvChatWorld(dis);
						break;
					// 战场
					case GameProtocol.SC_BATTLEFIELD_SCORES:
						// recvChatInfos(dis);
						UIWindows.getInstance().m_battlefield.recvScore(dis);
						break;
					case GameProtocol.SC_BATTLEFIELD_PRIZE:
						// recvChatWorld(dis);
						UIWindows.getInstance().m_battlefield.recvOVER(dis);
						break;
					// 竞技场
					case GameProtocol.S_ARENA_REQUEST:
						UIWindows.getInstance().m_jingji.recvIsImmediatelyInto(dis);
						break;
					case GameProtocol.S_ARENA_COUNTDOWN:
						UIWindows.getInstance().m_jingji.recvDJS(dis);
						break;
					case GameProtocol.S_ARENA_OVER:
						UIWindows.getInstance().m_jingji.recvOVER(dis);
						break;
					case GameProtocol.SC_FAMILY_ARENA_ROLE_AMOUNT:
						UIWindows.getInstance().m_jingji
								.recvFamilyArenaRoleAmount(dis);
						break;
					case GameProtocol.S_ARENA_CANCEL:
						UIWindows.getInstance().m_assistant.recvActivityQuit(dis);
						break;
					case GameProtocol.SC_FAMILY_REMOVE:
						UIWindows.getInstance().m_jingji.recvFamilyRemove(dis);
						break;
					// 其它人物信息
					case GameProtocol.SC_ROLE_INFO:
						Tools.debugPrintln("recv 查看其他人信息"
								+ GameProtocol.SC_ROLE_INFO);
						UIWindows.getInstance().m_rolestats.recvOtherRoleInfo(dis);
						break;
					///修罗杀场
					case GameProtocol.SC_SHURABATTLE_NPC:
						UIWindows.getInstance().m_shura_battle.recvNPC(dis);
						Tools.debugPrintln("收到NPC身上进入杀场的指令：" + GameProtocol.SC_SHURABATTLE_NPC);
						break;
					case GameProtocol.SC_SHURA_BATTLE_JOIN:
						UIWindows.getInstance().m_shura_battle.recvBattleJoin(dis);
						Tools.debugPrintln("收到进入杀场的指令：" + GameProtocol.SC_SHURA_BATTLE_JOIN);
						break;
					case GameProtocol.SC_BG_SCORE:
						UIWindows.getInstance().m_shura_battle.recvBattleJiShiScore(dis);
						Tools.debugPrintln("收到即时分数的指令：" + GameProtocol.SC_BG_SCORE);
						break;
					case GameProtocol.SC_ZHONGTU_LEAVE:
						UIWindows.getInstance().m_shura_battle.recvExitBattlefield(dis);
						Tools.debugPrintln("收到中途退出的奖励指令：" + GameProtocol.SC_ZHONGTU_LEAVE);
						break;
					case GameProtocol.SC_GAME_OVEW:
						UIWindows.getInstance().m_shura_battle.recvSettleAccounts(dis);
						Tools.debugPrintln("收到结算奖励指令：" + GameProtocol.SC_GAME_OVEW);
						break;
					case GameProtocol.SC_LEAVE:
						UIWindows.getInstance().m_shura_battle.recvLeave(dis);
						Tools.debugPrintln("收到退出战场的指令：" + GameProtocol.SC_LEAVE);
						break;
					case GameProtocol.SC_DJS:
						UIWindows.getInstance().m_shura_battle.recvDJS(dis);
						Tools.debugPrintln("收到退出战场的指令：" + GameProtocol.SC_DJS);
						break;
					// 排行榜
					case GameProtocol.SC_RANKINGLIST_LEVEL:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 等级排行榜");
							UIWindows.getInstance().m_rank
									.recvLevelRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_FAMILY:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 家族排行榜");
							UIWindows.getInstance().m_rank
									.recvFamilyRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_WEALTH:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 财富排行榜");
							UIWindows.getInstance().m_rank
									.recvWealthRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_KILL:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 击杀排行榜");
							UIWindows.getInstance().m_rank.recvKillRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_CONTRIBUTION:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 贡献排行榜");
							UIWindows.getInstance().m_rank
									.recvContrbutionRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_MILITARY_EXPLOITS:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 战功排行榜");
							UIWindows.getInstance().m_rank
									.recvMilitaryExploitsRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_SOCIAL_CONTACT:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 社交排行榜");
							UIWindows.getInstance().m_rank
									.recvSocialContactRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_INDIVIDUAL_SPORTS:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 个人竞技排行榜");
							UIWindows.getInstance().m_rank
									.recvIndividualSportsRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_FAMILY_SPORTS:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 家族竞技排行榜");
							UIWindows.getInstance().m_rank
									.recvFamilySportsRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_MARRIAGE:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 婚姻排行榜");
							UIWindows.getInstance().m_rank
									.recvMarriageRankingList(dis);
						}
						break;
					case GameProtocol.SC_RANKINGLIST_ZHANLI:
						if (UIWindows.getInstance().m_rank != null) {
							Tools.debugPrintln("recv 战力排行榜");
							UIWindows.getInstance().m_rank
									.recvZhanLiRankingList(dis);
						}
						break;
					// 角色死亡
					case GameProtocol.SC_DEAD_POPUPS:
						Tools.debugPrintln("recv 角色死亡"
								+ GameProtocol.SC_DEAD_POPUPS);
						UIWindows.getInstance().m_relive.recvRoleDead(dis);
						break;
					case GameProtocol.SC_REVIVE_CONFIRMATION:
						Tools.debugPrintln("recv 其他人复活"
								+ GameProtocol.SC_REVIVE_CONFIRMATION);
						UIWindows.getInstance().m_relive.recvRoleOtherRelive(dis);
						break;
					case GameProtocol.SC_REVIVE_POS:
						Tools.debugPrintln("recv 复活角色"
								+ GameProtocol.SC_REVIVE_CONFIRMATION);
						UIWindows.getInstance().m_relive.recvRoleRliveStates(dis);
						break;
					case GameProtocol.SC_ACTORROLE_VIM:
						Tools.debugPrintln("recv 精力值");
						DWGameManager.getInstance().m_role.recvActorVim(dis);
						break;
					case GameProtocol.SC_ROLE_MONEY:
						recvRoleMoney(dis);
						break;
					case GameProtocol.SC_ROLE_EXP:
						recvRoleExp(dis);
						break;
					// 游戏公告
					case GameProtocol.SC_GAME_ANNOUNCEMENT:
						Tools.debugPrintln("recv 公告提示");
						UIWindows.getInstance().m_announ.recvAnnouncement(dis);
						break;
					case GameProtocol.SC_GAME_NOTICE_INFO:
						Tools.debugPrintln("recv 公告内容");
						UIWindows.getInstance().m_announ.recvAnnouncementInfos(dis);
						break;
					case GameProtocol.SC_SET_WEATHER_AND_MUSIC:
						Tools.debugPrintln("recv 天气和音乐");
						recvWEATHERANDMUSIC(dis);
						break;
					// 助手定时活动
					case GameProtocol.CS_ASSISTANT_ACTIVITY_OPEN:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.CS_ASSISTANT_ACTIVITY_OPEN);
						UIWindows.getInstance().m_assistant.recvDingShi(dis);
						break;
					case GameProtocol.SC_ASSISTANT_UPDATE_ICON:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.SC_ASSISTANT_UPDATE_ICON);
						UIWindows.getInstance().m_assistant.recvUpdateIcon(dis);
						break;
					case GameProtocol.SC_ASSISTANT_UPDATE_ICON_MORE:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.SC_ASSISTANT_UPDATE_ICON_MORE);
						UIWindows.getInstance().m_assistant.recvUpdateIconMore(dis);
						break;
					case GameProtocol.SC_ASSISTANT_ACTIVITY_LINEUP:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.SC_ASSISTANT_ACTIVITY_LINEUP);
						UIWindows.getInstance().m_assistant.recvActivityLineup(dis);
						break;
					case GameProtocol.SC_ASSISTANT_ACTIVITY_QUIT:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.SC_ASSISTANT_ACTIVITY_QUIT);
						UIWindows.getInstance().m_assistant.recvActivityQuit(dis);
						break;
					case GameProtocol.SC_ASSISTANT_ACTIVITY_COUNT:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.SC_ASSISTANT_ACTIVITY_COUNT);
						UIWindows.getInstance().m_assistant.recvActivityCount(dis);
						break;
					// 助手日常活动
					case GameProtocol.CS_ASSISTANT_EVERYDAY_OPEN:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.CS_ASSISTANT_EVERYDAY_OPEN);
						UIWindows.getInstance().m_assistant.recvEverydayList(dis);
						break;
					case GameProtocol.CS_ASSISTANT_EVERYDAY_ADD:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.CS_ASSISTANT_EVERYDAY_ADD);
						UIWindows.getInstance().m_assistant.recvEverydayAdd(dis);
						break;
					case GameProtocol.CS_ASSISTANT_OPERATE_OPEN:
						Tools.debugPrintln("recv 助手"
								+ GameProtocol.CS_ASSISTANT_OPERATE_OPEN);
						UIWindows.getInstance().m_assistant.recvOperateList(dis);
						break;
					case GameProtocol.SC_GUIDE:
						if (DWControlsManager.getInstance() != null) {
							DWControlsManager.getInstance().m_guides.recvGuide(dis);
						}
						break;
					case GameProtocol.SC_EXTRA_DAMAGE:
						recvExtraDamage(dis);
						break;
					case GameProtocol.SC_ASSISTANT_EVERYDAY_JIANGLI:
						UIWindows.getInstance().m_assistant.recvLingjiang(dis);
						break;
					// 请求打开vip商城返回
					case GameProtocol.SC_VIPSHOP_OPEN:
						UIWindows.getInstance().m_shop.recvOpenShop(dis);
						break;
					// 请求购买
					case GameProtocol.SC_VIPSHOP_BUY:
						UIWindows.getInstance().m_shop.recvBuyItemSucceed(dis);
						break;
					// 请求查看
					case GameProtocol.SC_VIPSHOP_ITEM:
						UIWindows.getInstance().m_shop.recvLookBuyItemSucceed(dis);
						break;
					// 请求打开vip返回
					case GameProtocol.SC_VIP_OPEN:
						UIWindows.getInstance().m_vip.recvOpenVIP(dis);
						break;
					// 请求vip等级描述
					case GameProtocol.SC_VIP_LEVEL:
						UIWindows.getInstance().m_vip.recvVipLevel(dis);
						break;
					// 请求vip礼包
					case GameProtocol.SC_LIBAO_OPEN:
						UIWindows.getInstance().m_vip.recvGetLi(dis);
						break;
					// 礼包倒计时
					case GameProtocol.SC_LIBAO_TIME:
						UIWindows.getInstance().m_main.recvGetTime(dis);
						break;
					case GameProtocol.SC_GIFT_BAG_OPEN:
						Tools.debugPrintln("接收开启兑换窗口" + order + "!");
						recvGiftBagOpen(dis);
						break;
					case GameProtocol.SC_NPC_USER_CHANGE_PASSWORD:
						UIWindows.getInstance().m_main.recvNpcUser(UIWindows
								.getInstance().m_main.ACCOUNT_MANAGE_PASSWORD);
						break;
					case GameProtocol.SC_NPC_USER_BINDING:
						UIWindows.getInstance().m_main.recvNpcUser(UIWindows
								.getInstance().m_main.ACCOUNT_MANAGE_BINDING);
						break;
					case GameProtocol.SC_NPC_USER_RETRIEVE_PASSWORD:
						UIWindows.getInstance().m_main.recvNpcUser(UIWindows
								.getInstance().m_main.ACCOUNT_MANAGE_BACK);
						break;
					case GameProtocol.SC_NPC_USER_UNBIND:
						UIWindows.getInstance().m_main.recvNpcUser(UIWindows
								.getInstance().m_main.ACCOUNT_MANAGE_UNBIND);
						break;
					case GameProtocol.SC_USER_CHANGE_PASSWORD:
						Tools.debugPrintln("修改密码："
								+ GameProtocol.SC_USER_CHANGE_PASSWORD);
						recvChangePassword(dis);
						break;
					case GameProtocol.SC_USER_BINDING:
						Tools.debugPrintln("账号绑定：" + GameProtocol.SC_USER_BINDING);
						recvAccountBinding(dis);
						break;
					case GameProtocol.SC_USER_UNBIND:
						Tools.debugPrintln("账号解除绑定：" + GameProtocol.SC_USER_UNBIND);
						recvAccountUnbind(dis);
						break;
					case GameProtocol.SC_USER_RETRIEVE_PASSWORD:
						Tools.debugPrintln("找回密码："
								+ GameProtocol.SC_USER_RETRIEVE_PASSWORD);
						recvRetrievePassword(dis);
						break;
					case GameProtocol.SC_SCENE_PUSH_CAST:
						Tools.debugPrintln("世界地图读条");
						UIMap.recvTransitTime(dis);
						break;
					// 交易
					case GameProtocol.SC_TRANSACTION_OPEN:
						if (UIWindows.getInstance().m_exchang != null) {
							UIWindows.getInstance().m_exchang
									.recvTranActionOpen(dis);
						}
						break;
					case GameProtocol.SC_TRANSACTION_CLOCK:
						Tools.debugPrintln("双方锁定状态："
								+ GameProtocol.SC_TRANSACTION_CLOCK);
						if (UIWindows.getInstance().m_exchang != null) {
							UIWindows.getInstance().m_exchang
									.recvTranActionClock(dis);
						}
						break;
					// case GameProtocol.SC_TRANSACTION_CLOCK_TARGET:
					// if(UIWindows.getInstance().m_exchang != null){
					// UIWindows.getInstance().m_exchang.recvTranActionClockTarget(dis);
					// }
					// break;
					case GameProtocol.SC_TRANSACTION_TARGET_RESULT:
						Tools.debugPrintln("双方交易确定状态："
								+ GameProtocol.SC_TRANSACTION_TARGET_RESULT);
						if (UIWindows.getInstance().m_exchang != null) {
							UIWindows.getInstance().m_exchang
									.recvTranActionTargetComFirm(dis);
						}
						break;
					case GameProtocol.SC_TRANSACTION_TARGETLIST:
						Tools.debugPrintln("目标交易物品列表"
								+ GameProtocol.SC_TRANSACTION_TARGETLIST);
						if (UIWindows.getInstance().m_exchang != null) {
							UIWindows.getInstance().m_exchang
									.recvTranActionTargetList(dis);
						}
						break;
					case GameProtocol.SC_TRANSACTION_REQUEST:
						Tools.debugPrintln("目标请求与你交易"
								+ GameProtocol.SC_TRANSACTION_REQUEST);
						if (UIWindows.getInstance().m_exchang != null) {
							UIWindows.getInstance().m_exchang
									.recvTranActionTargetRequest(dis);
						}
						break;
					case GameProtocol.SC_TRANSACTION_RESULT:
						Tools.debugPrintln("最终交易结果"
								+ GameProtocol.SC_TRANSACTION_RESULT);
						if (UIWindows.getInstance().m_exchang != null) {
							UIWindows.getInstance().m_exchang
									.recvTranActionResult(dis);
						}
						break;
					case GameProtocol.CS_CHONGZHI_CONFIG:
						UIWindows.getInstance().m_recharge.recvChongZhi(dis);
						break;
					case GameProtocol.CS_QUERY_CHONGZHI:
						UIWindows.getInstance().m_recharge.recvChongzhiRecord(dis);
						break;
					case GameProtocol.CS_QUERY_YUANBAO_CONSUME:
						UIWindows.getInstance().m_recharge.recvConsumeRecord(dis);
						break;
					case GameProtocol.SC_GET_CHONGZHIJILU:
						UIWindows.getInstance().m_record.recvGetChongZhiJiLu(dis);
						break;
					// /帮贡购买
					case GameProtocol.SC_HELP_GONG_COUNT:
						UIWindows.getInstance().m_help_gong.recvHelpGongCount(dis);
						Tools.debugPrintln("收到指令："
								+ GameProtocol.SC_HELP_GONG_COUNT);
						break;
					case GameProtocol.SC_HELP_GONG_BUY:
						UIWindows.getInstance().m_help_gong.recvSubmitBuy(dis);
						Tools.debugPrintln("收到指令：" + GameProtocol.SC_HELP_GONG_BUY);
						break;
					// /购买个人竞技次数
					case GameProtocol.SC_ADD_COUNT:
						UIWindows.getInstance().m_assistant.recvAddCount(dis);
						Tools.debugPrintln("收到指令：" + GameProtocol.SC_ADD_COUNT);
						break;
					case GameProtocol.SC_ADD_BUY:
						UIWindows.getInstance().m_assistant.recvAddBuy(dis);
						Tools.debugPrintln("收到指令：" + GameProtocol.SC_ADD_BUY);
						break;
					// ///购买每日任务次数
					case GameProtocol.SC_ADD_EVERYDAY_BUY:
						UIWindows.getInstance().m_renwu.recvAddEverydayBuy(dis);
						Tools.debugPrintln("收到指令："
								+ GameProtocol.SC_ADD_EVERYDAY_BUY);
						break;
					case GameProtocol.SC_ADD_EVERYDAY_JINDU_COUNT:
						UIWindows.getInstance().m_renwu
								.recvEverydayNormalCount(dis);
						Tools.debugPrintln("收到指令："
								+ GameProtocol.SC_ADD_EVERYDAY_JINDU_COUNT);
						break;
					case GameProtocol.SC_CHANGJING_TIME:
						UIWindows.getInstance().m_jingji.recvChangjingTime(dis);
						Tools.debugPrintln("收到场景倒计时时间的指令："
								+ GameProtocol.SC_CHANGJING_TIME);
						break;
					///塔式副本
					case GameProtocol.SC_TOWER_GAMECARBON_OPEN:
						UIWindows.getInstance().m_tower.recvOpenTowerGamecarbon(dis);
						Tools.debugPrintln("收到开启塔式副本指令："
								+ GameProtocol.SC_TOWER_GAMECARBON_OPEN);
						break;
					case GameProtocol.SC_TOWER_GAMECARBON_JIANG:
						UIWindows.getInstance().m_tower.recvLoseJiangLi(dis);
						Tools.debugPrintln("收到查看掉落奖励指令："
								+ GameProtocol.SC_TOWER_GAMECARBON_JIANG);
						break;
					case GameProtocol.SC_TOWER_GAMECARBON_JOIN:
						UIWindows.getInstance().m_tower.recvJoinGamecarbon(dis);
						Tools.debugPrintln("收到进入副本的指令："
								+ GameProtocol.SC_TOWER_GAMECARBON_JOIN);
						break;
					case GameProtocol.SC_TOWER_ZHUANPAN_OPEN:
						UIWindows.getInstance().m_tower.recvTowerZhuanPanOpen(dis);
						Tools.debugPrintln("收到转盘界面开启的指令："
								+ GameProtocol.SC_TOWER_ZHUANPAN_OPEN);
						break;
					case GameProtocol.SC_TOWER_ZHUANPAN_SUODING:
						UIWindows.getInstance().m_tower.recvTowerZhuanPanSouding(dis);
						Tools.debugPrintln("收到转盘锁定的指令："
								+ GameProtocol.SC_TOWER_ZHUANPAN_SUODING);
						break;
					case GameProtocol.SC_TOWER_ZHUANPAN_END:
						UIWindows.getInstance().m_tower.recvZhuanPanEnd(dis);
						Tools.debugPrintln("收到转盘旋转结果的指令："
								+ GameProtocol.SC_TOWER_ZHUANPAN_END);
						break;
					case GameProtocol.SC_TOWER_TONGGUAN_JIANGLI:
						UIWindows.getInstance().m_tower.recvWin(dis);
						Tools.debugPrintln("收到通关的指令："
								+ GameProtocol.SC_TOWER_TONGGUAN_JIANGLI);
						break;
					case GameProtocol.SC_TOWER_XIAYICENG_INFORMATION:
						UIWindows.getInstance().m_tower.recvEveryPriceWin(dis);
						Tools.debugPrintln("收到每下一小节的信息的指令："
								+ GameProtocol.SC_TOWER_XIAYICENG_INFORMATION);
						break;
					case GameProtocol.SC_TOWER_JOIN_NEXTCENG:
						UIWindows.getInstance().m_tower.recvJoinNextCeng(dis);
						Tools.debugPrintln("收到进入下一小节的指令："
								+ GameProtocol.SC_TOWER_JOIN_NEXTCENG);
						break;
					case GameProtocol.SC_TOWER_LEAVE_GAMECARBON:
						UIWindows.getInstance().m_tower.recvLeaveGamecarbon(dis);
						Tools.debugPrintln("收到离开副本的指令："
								+ GameProtocol.SC_TOWER_LEAVE_GAMECARBON);
						break;
					case GameProtocol.SC_TOWER_MORE_GAMECARBON:
						UIWindows.getInstance().m_tower.recvMoreGamecarbon(dis);
						Tools.debugPrintln("收到重置副本的指令："
								+ GameProtocol.SC_TOWER_MORE_GAMECARBON);
						break;
					// //////
					// 婚姻
					// //////
					case GameProtocol.SC_OPEN_PROPOSE_UI:
						Tools.debugPrintln("请求打开求婚界面"
								+ GameProtocol.SC_OPEN_PROPOSE_UI);
						UIWindows.getInstance().m_marriage.recvMarriageOpenUI(dis);
						break;
					case GameProtocol.SC_MARRIAGE_PROPOSE_APPLICATION:
						Tools.debugPrintln("求婚申请"
								+ GameProtocol.SC_MARRIAGE_PROPOSE_APPLICATION);
						UIWindows.getInstance().m_marriage.recvMarriageConfirm(dis);
						break;
					case GameProtocol.SC_MARRIAGE_PROPOSE_REQUEST:
						Tools.debugPrintln("被求婚"
								+ GameProtocol.SC_MARRIAGE_PROPOSE_REQUEST);
						UIWindows.getInstance().m_marriage.recvMarriageRequest(dis);
						break;
					case GameProtocol.SC_MARRIAGE_PROPOSE_RESULT:
						Tools.debugPrintln("求婚结果"
								+ GameProtocol.SC_MARRIAGE_PROPOSE_RESULT);
						UIWindows.getInstance().m_marriage.recvMarriageResult(dis);
						break;
					case GameProtocol.SC_MARRIAGE_DIVORCE_APPLICATION:
						Tools.debugPrintln("离婚申请"
								+ GameProtocol.SC_MARRIAGE_DIVORCE_APPLICATION);
						UIWindows.getInstance().m_marriage
								.recvDivorceApplication(dis);
						break;
					case GameProtocol.SC_MARRIAGE_DIVORCE_RESULT:
						Tools.debugPrintln("离婚结果"
								+ GameProtocol.SC_MARRIAGE_DIVORCE_RESULT);
						UIWindows.getInstance().m_marriage.recvDivorceResult(dis);
						break;
					case GameProtocol.SC_MARRIAGE_MESSAGE:
						Tools.debugPrintln("婚姻信息"
								+ GameProtocol.SC_MARRIAGE_MESSAGE);
						DWGameManager.getInstance().m_role.recvMarriageMessage(dis);
						break;
					case GameProtocol.SC_MARRIAGE_LV:
						Tools.debugPrintln("婚姻等级" + GameProtocol.SC_MARRIAGE_LV);
						DWGameManager.getInstance().m_role.recvMarriageLv(dis);
						break;
					case GameProtocol.SC_MARRIAGE_EXP:
						Tools.debugPrintln("夫妻友好度" + GameProtocol.SC_MARRIAGE_EXP);
						DWGameManager.getInstance().m_role.recvMarriageExp(dis);
						break;
					case GameProtocol.SC_MARRIAGE_TRANSFER_CD:
						Tools.debugPrintln("夫妻传送冷却时间冷却时间"
								+ GameProtocol.SC_MARRIAGE_TRANSFER_CD);
						DWGameManager.getInstance().m_role.recvTransferCD(dis);
						break;
					// //////
					// 婚姻end
					// //////
					case GameProtocol.SC_PRIZE_MESSAGE:
						Tools.debugPrintln("收到指令：" + GameProtocol.SC_PRIZE_MESSAGE);
						UIWindows.getInstance().m_prize.recvPrizeMessage(dis);
						break;
					case GameProtocol.SC_PRIZE_LIST:
						Tools.debugPrintln("收到指令：" + GameProtocol.SC_PRIZE_MESSAGE);
						UIWindows.getInstance().m_prize.recvPrizeList(dis);
						break;
					case GameProtocol.SC_PRIZE_APPLY:
						Tools.debugPrintln("收到指令：" + GameProtocol.SC_PRIZE_MESSAGE);
						UIWindows.getInstance().m_prize.recvPrizeApply(dis);
						break;
					// /////
					case GameProtocol.SC_OPEN_PANEL:
						Tools.debugPrintln("宠物坐骑消失" + GameProtocol.SC_OPEN_PANEL);
						UIWindows.getInstance().m_bag.recvOpenPanel(dis);
						break;
					case GameProtocol.SC_OPEN_WAREHOUSE:
						Tools.debugPrintln("打开仓库" + GameProtocol.SC_OPEN_WAREHOUSE);
						UIWindows.getInstance().m_warehouse.recvOpenWarehouse(dis);
						break;
					// 师徒
					case GameProtocol.SC_TEACHERPUPIL_BAISHI:// 拜师
						Tools.debugPrintln("拜师"
								+ GameProtocol.SC_TEACHERPUPIL_BAISHI);
						UIWindows.getInstance().m_social.recvBaiShi(dis);
						break;
					// 师父决定
					case GameProtocol.SC_TEACHERPUPIL_JIESHOU://
						Tools.debugPrintln("决定"
								+ GameProtocol.SC_TEACHERPUPIL_JIESHOU);
						UIWindows.getInstance().m_social.recvHuiDa(dis);
						break;
					// 通用
					case GameProtocol.SC_TEACHERPUPIL_TONGYONG://
						Tools.debugPrintln("通用"
								+ GameProtocol.SC_TEACHERPUPIL_TONGYONG);
						UIWindows.getInstance().m_social.recvTongYong(dis);
						break;
					// 传功请求
					case GameProtocol.SC_TEACHERPUPIL_CHUANGONG://
						Tools.debugPrintln("传功请求"
								+ GameProtocol.SC_TEACHERPUPIL_CHUANGONG);
						UIWindows.getInstance().m_social.recvChuanGong(dis);
						break;
					// 传功应答
					case GameProtocol.SC_TEACHERPUPIL_CHUANGONGYINGDA://
						Tools.debugPrintln("传功请求"
								+ GameProtocol.SC_TEACHERPUPIL_CHUANGONGYINGDA);
						UIWindows.getInstance().m_social.recvGetChuanGong(dis);
						break;
					case GameProtocol.SC_TEACHERPUPIL_OPEN:
						Tools.debugPrintln("打开师徒"
								+ GameProtocol.SC_TEACHERPUPIL_OPEN);
						UIWindows.getInstance().m_social.recvPupilList(dis);
						break;
					case GameProtocol.SC_TEACHERPUPIL_CHUANGONGJINDUTIAO:
						Tools.debugPrintln("打开师徒"
								+ GameProtocol.SC_TEACHERPUPIL_OPEN);
						UIWindows.getInstance().m_social.recvGetChuanGongTotal(dis);
						break;
					case GameProtocol.SC_TEACHERPUPIL_CHANGMESSAGE:
						Tools.debugPrintln("更新师徒信息"
								+ GameProtocol.SC_TEACHERPUPIL_CHANGMESSAGE);
						DWGameManager.getInstance().m_role.recvShituMessage(dis);
						break;
					// 道具使用粒子效果
					case GameProtocol.SC_USEITEM_PARTICLE:
						Tools.debugPrintln("道具使用粒子效果："
								+ GameProtocol.SC_USEITEM_PARTICLE);
						recvUseParticle(dis);
						break;
					// 八卦炉 //
					case GameProtocol.SC_BAGUALU_WD_CLT:
						UIWindows.getInstance().m_bagualu.recvBaGuaLu(dis);
						Tools.debugPrintln("收到指令："
								+ GameProtocol.SC_BAGUALU_WD_CLT);
						break;
					//炼魂
					case GameProtocol.SC_OPEN_SOUL_BY_INDEX:
						Tools.debugPrintln("打开指定炼魂页："
								+ GameProtocol.SC_OPEN_SOUL_BY_INDEX);
						if (UIWindows.getInstance().m_soul != null) {
							UIWindows.getInstance().m_soul.recvOpenSoulListByIndex(dis);
						}
						break;
					case GameProtocol.SC_SEE_SOUL_BY_INDEX:
						Tools.debugPrintln("查看指定魂页某个魂点信息："
								+ GameProtocol.SC_SEE_SOUL_BY_INDEX);
						if (UIWindows.getInstance().m_soul != null) {
							UIWindows.getInstance().m_soul.recvSoulByIndex(dis);
						}
						break;
					case GameProtocol.SC_PROMOTE_SOUL_LEVEL:
						Tools.debugPrintln("升级魂点是否成功："
								+ GameProtocol.SC_PROMOTE_SOUL_LEVEL);
						if (UIWindows.getInstance().m_soul != null) {
							UIWindows.getInstance().m_soul.recvPromoteSoulResult(dis);
						}
						break;
					case GameProtocol.SC_SCENE_MAP:
						UIMap.recvSceneMap(dis);
						break;

					//抽奖
					case GameProtocol.SC_OPEN_LUCKDRAW:
						Tools.debugPrintln("revc打开抽奖" + GameProtocol.SC_OPEN_LUCKDRAW);
						UIWindows.getInstance().m_luckdraw.readLuckDrawOpen(dis);
						break;
					case GameProtocol.SC_LUCKDRAW_START:
						Tools.debugPrintln("revc开始抽奖" + GameProtocol.SC_LUCKDRAW_START);
						UIWindows.getInstance().m_luckdraw.readLuckDrawResult(dis);
						break;
					case GameProtocol.SC_LUCKDRAW_ADDNUM:
						Tools.debugPrintln("revc抽奖增次" + GameProtocol.SC_LUCKDRAW_ADDNUM);
						UIWindows.getInstance().m_luckdraw.readLuckDrawAddResult(dis);
						break;
					case GameProtocol.SC_LUCKDRAW_RESULT:
						Tools.debugPrintln("revc抽奖结果" + GameProtocol.SC_LUCKDRAW_RESULT);
						UIWindows.getInstance().m_luckdraw.readLuckDrawGetResult(dis);
						break;
					//推荐
					case GameProtocol.SC_TUIJIAN_HAOYOU:
						Tools.debugPrintln("revc推荐好友" + GameProtocol.SC_TUIJIAN_HAOYOU);
						UIWindows.getInstance().m_tuijian.readTuijianHaoyou(dis);
						break;
					case GameProtocol.SC_TUIJIAN_TUDI:
						Tools.debugPrintln("revc推荐徒弟" + GameProtocol.SC_TUIJIAN_TUDI);
						UIWindows.getInstance().m_tuijian.readTuijianTudi(dis);
						break;
					case GameProtocol.SC_TUIJIAN_SHIFU:
						Tools.debugPrintln("revc推荐师傅" + GameProtocol.SC_TUIJIAN_SHIFU);
						UIWindows.getInstance().m_tuijian.readTuijianShifu(dis);
						break;
					case GameProtocol.S_USER_REFERSH:
						//注释掉。。
//						ChannelOperation.recvUserrefresh(dis);
						break;
					//首充奖励
					case GameProtocol.SC_RECHARGE_TISHI:
						Tools.debugPrintln("revc首充提示" + GameProtocol.SC_RECHARGE_TISHI);
						UIWindows.getInstance().m_firstRecharge.recvRechargeTishi(dis);
						/////////////////////
						break;
					case GameProtocol.SC_RECHARGE_PRIZE:
						Tools.debugPrintln("revc请求首充领奖详情" + GameProtocol.SC_RECHARGE_PRIZE);
						UIWindows.getInstance().m_firstRecharge.recvRechargeItem(dis);
						break;
					//装备锻造
					case GameProtocol.SC_EQUIPMENT_FORGE:
						Tools.debugPrintln("revc请求装备锻造" + GameProtocol.SC_EQUIPMENT_FORGE);
						UIWindows.getInstance().m_tiangong.recvEquipmentForge(dis);
						break;
					case GameProtocol.SC_EQUIPMENT_OPEN:
						Tools.debugPrintln("revc接收锻造属性" + GameProtocol.SC_EQUIPMENT_OPEN);
						UIWindows.getInstance().m_tiangong.recvEquipmentOpen(dis);
						break;
					case GameProtocol.SC_RECHARGE_REMOVE:
						Tools.debugPrintln("revc首充后移除图标" + GameProtocol.SC_RECHARGE_REMOVE);
						UIWindows.getInstance().m_firstRecharge.recvRechargeRemove(dis);
						break;
				////////////////////////////////
				}
			}
			catch (Exception e) {
				Tools.debug(e);
			}
			return false;
		}

		public boolean doClick(PointF point)
		{
			float x1 = point.x;
			float y1 = point.y;
			if (DWGameManager.getInstance().m_role.m_scene == null)
				return true;
			boolean MySell = m_controlledActor.isSellStatus();
			if (!DWControlsManager.getInstance().doClick(x1, y1)) {
				UIHook.closeHook();
				DWGameManager.getInstance().m_role.breakAutoAttack();
				x1 = point.x
						+ DWGameManager.getInstance().m_role.m_scene.m_cameraX;
				y1 = point.y
						+ DWGameManager.getInstance().m_role.m_scene.m_cameraY;
				GameActor clickActor = isClickNpc(new PointF(x1, y1));
				// 点击到GameActor
				if (clickActor != null) {
					setTargetActor(clickActor);
					if (clickActor.m_gameId != DWGameManager.getInstance().m_role.m_gameId) {
						// 如果自己处于摆摊中无法操作选中
						if (MySell) {
							setTargetActor(null);
							DWGameManager.getInstance().addSystemInfo(
									DWGameManager.SYSTEM_INFO_TYPE_B,
									"摆摊中，无法操作！");
							return false;
						}
						// 如果点击的是角色并且不是玩家自己并且角色是摆摊中
						if (clickActor instanceof Role) {
							Role r = (Role) clickActor;
							if (r.isOtherSellStatus()) {
								UIWindows.getInstance().m_baitan
										.sendBaitanChakan(r.m_gameId);
								return true;
							}
						}
						// 点击到的GameActor在交互范围内
						if (Tools.distanceSquare(m_controlledActor.m_posX,
								m_controlledActor.m_posY, clickActor.m_posX,
								clickActor.m_posY) <= GameActorConstants.INTERACTION_RANGE) {
							switch (clickActor.m_type) {
								case GameActorConstants.ACTOR_TYPE_NPC:
								case GameActorConstants.ACTOR_TYPE_GATHERING:
									DWGameManager.getInstance().getSendMessage()
											.sendNPCList(clickActor.m_gameId);
									break;
							}
						}
						// 点击到的GameActor不在交互范围内
						else {
							if (clickActor.m_type == GameActorConstants.ACTOR_TYPE_NPC
									|| clickActor.m_type == GameActorConstants.ACTOR_TYPE_GATHERING
									|| clickActor.m_type == GameActorConstants.ACTOR_TYPE_ROLE) {
								DWGameManager.getInstance().m_role
										.doPath(new PointF(x1, y1));

							}
						}
					}
					else {
						// 选中的是自己
						if (MySell) {
							UIWindows.getInstance().m_baitan
									.sendBaitanChakan(m_controlledActor.m_gameId);
						}
					}
				}
				// 未点击到GameActor
				else {
					// 如果自己处于摆摊中无法操作选中
					if (MySell) {
						DWGameManager.getInstance().addSystemInfo(
								DWGameManager.SYSTEM_INFO_TYPE_B, "摆摊中，无法操作！");
						return false;
					}
					Background background = m_scene.m_bg;
					int start = BinHeapAStar.convertXYtoPoint(
							DWGameManager.getInstance().m_role.m_posX,
							DWGameManager.getInstance().m_role.m_posY,
							background.m_tileW, background.m_tileH,
							background.m_columns);
					int end = BinHeapAStar.convertXYtoPoint((int) x1, (int) y1,
							background.m_tileW, background.m_tileH,
							background.m_columns);
					int[] m_pathfinding_paths = BinHeapAStar.findPath(
							background.getPhyData(), background.m_columns,
							background.m_rows, start, end);
					if (m_pathfinding_paths != null) {
						s_clickMove.setAction(0, true);
						s_clickMove.m_posX = (int) x1;
						s_clickMove.m_posY = (int) y1;
						s_clickMove.setEnabled(true);
						DWGameManager.getInstance().m_role.doPath(new PointF(
								x1, y1));
					}
					else {
						s_clickMove.setAction(1, true);
						s_clickMove.m_posX = (int) x1;
						s_clickMove.m_posY = (int) y1;
						s_clickMove.setEnabled(true);
					}
				}
			}
			return true;
		}

		public boolean doScroll(PointF start, PointF end, float distanceX,
				float distanceY)
		{
			DWControlsManager.getInstance().doScroll(start, end, distanceX,
					distanceY);
			// float disX = end.x - start.x;
			// float disY = end.y - start.y;
			// if (disX >= disY) {
			// tx = (int) (m_cameraX + end.x);
			// m_destCameraX = tx - (m_cameraW >> 1);
			// }
			// else {
			// ty = (int) (m_cameraY + end.y);
			// m_destCameraY = ty - (m_cameraH >> 1);
			// }
			return true;
		}

		public boolean doDoubleClick(PointF point)
		{
			DWControlsManager.getInstance().doDoubleClick(point);
			return false;
		}

		public boolean doLongPress(PointF point)
		{
			DWControlsManager.getInstance().doLongPress(point);
			return false;
		}

		public boolean doDrag(PointF start, PointF end, float velocityX,
				float velocityY)
		{
			DWControlsManager.getInstance().doDrag(start, end, velocityX,
					velocityY);
			return false;
		}

		public boolean doDown(PointF point)
		{
			DWControlsManager.getInstance().doDown(point);
			return false;
		}

		public boolean doLongScroll(PointF start, PointF end, float distanceX,
				float distanceY)
		{
			DWControlsManager.getInstance().doLongScroll(start, end, distanceX,
					distanceY);
			return false;
		}

		public boolean doFling(PointF start, PointF end, float velocityX,
				float velocityY)
		{
			DWControlsManager.getInstance().doFling(start, end, velocityX,
					velocityY);
			return false;
		}

		private long start;
		private long end;
		private long drawtime1, drawtime2, drawtime3;

		public void paint(DWGraphics g)
		{
			g.setClip(0, 0, DWGameManager.Screen_Width,
					DWGameManager.Screen_Height);
			// g.setColor(0xff, 0, 0, 0);
			// g.fillRect(0, 0, DWGameManager.Screen_Width,
			// DWGameManager.Screen_Height);
			int startLayer = 0;
			int endLayer = 0;
			if (m_actorLayers.length == 0) {
				if (m_bg != null) {
					// g.setColor(m_bg.m_color);
					// g.fillRect(0, 0, m_cameraW, m_cameraH);
					if (m_bg.m_isUseBuffer) {
						m_bg.drawBuffer(g, 0, m_bg.m_layerCount - 1);
					}
					else {
						m_bg.draw(g, 0, m_bg.m_layerCount - 1);
					}
				}
				drawActor(g, 0);
			}
			else {
				for (int i = 0; i < m_actorLayers.length; i++) {
					endLayer = m_actorLayers[i];
					if (m_bg != null && endLayer >= startLayer) {
						// if (i == 0) {
						// g.setColor(m_bg.m_color);
						// g.fillRect(0, 0, m_cameraW, m_cameraH);
						// }
						if (m_bg.m_isUseBuffer && i == 0) {
							m_bg.drawBuffer(g, startLayer, endLayer);
						}
						else {
							m_bg.draw(g, startLayer, endLayer);
						}
					}
					drawActor(g, i);
					startLayer = endLayer + 1;
				}
			}

			showSkillResultList(g);

			DWControlsManager.getInstance().paint(g);

			drawPromptUpgradeAnim(g);

			UIWindows.getInstance().drawBaGua(g);

			showMessage(g);

			paintFPS(g);

			showCutin(g);

			drawParticle(g);

			drawParticleList(g);

			showMessageB(g);
		}

		public void init()
		{
			Tools.debugPrintln("初始化scene_init");
			setRunning(true);
			initStaticResource();
//			ParticleConstants.initResource();
			m_isPainting = true;
			m_isRepaintOnce = false;
			m_cameraW = DWGameManager.Screen_Width;
			m_cameraH = DWGameManager.Screen_Height;
			m_bgWidth = m_bg.m_tileW * m_bg.m_columns;
			m_bgHeight = m_bg.m_tileH * m_bg.m_rows;
			m_cameraLimitX = 0;
			m_cameraLimitY = 0;
			m_cameraLimitW = Math.max(0, m_bgWidth - m_cameraW);
			m_cameraLimitH = Math.max(0, m_bgHeight - m_cameraH);
			boolean useBuffer = true;
			int firstActorLayer = 0;
			if (m_actorLayers.length > 0) {
				firstActorLayer = m_actorLayers[0];
			}
			else {
				firstActorLayer = m_bg.m_layerCount - 1;
			}
			if (m_bg.m_layers != null) {
				for (int j = 0; j <= firstActorLayer; j++) {
					if (m_bg.m_layers[j] != null
							&& m_bg.m_layers[j].m_type != Layer.TYPE_TILEDLAYER
							&& m_bg.m_layers[j].m_type != Layer.TYPE_PHYSICALLAYER) {
						useBuffer = false;
						break;
					}
				}
				m_bg.m_isUseBuffer = useBuffer;
			}

			m_bg.setCameraWH(m_cameraW, m_cameraH);
			m_bg.initResource();

			m_img_thumbnail = Bitmap.createBitmap(m_bgWidth
					/ THUMBNAIL_ZOOM_RATIO, m_bgHeight / THUMBNAIL_ZOOM_RATIO,
					Config.RGB_565);
			m_graphics_thumbnail = new DWGraphics(m_img_thumbnail);
			paintScene(1 / (float) THUMBNAIL_ZOOM_RATIO,
					1 / (float) THUMBNAIL_ZOOM_RATIO);

			// 场景初始化
			m_dynamicActors.clear();
			m_activeList.clear();
			m_drawList.clear();
			m_skillResultShow_list.clear();
			m_targetEnemyList.clear();
			m_targetFriendList.clear();
			// 初始化effect
			if (GameEffect.s_effect == null) {
				GameEffect.initStaticResource();
			}
			GameEffect.s_effect.m_scene = m_scene;
			// 场景中关于玩家角色的初始化
			Role role = DWGameManager.getInstance().m_role;
			role.m_posX = role.m_prevPosX = DWGameManager.getInstance().m_role_x;
			role.m_posY = role.m_prevPosY = DWGameManager.getInstance().m_role_y;
			Tools.debugPrintln("GameScene init role status : " + role.m_status);
			// initRoleAnims();
			if (role.m_status == Role.ACTOR_STATUS_DEAD) {
				role.setAction(Role.ACTION_DEAD * Role.DIRECT_NUM, 0, 0, false,
						true);
			}
			else {
				role.stay(role.m_direct);
			}
			role.activate();
			role.m_targetActor = null;
			m_controlledActor = role;
			m_focusActor = role;

			s_targetFrame.m_layer = m_actorMovableLayer;
			s_clickMove.m_layer = m_actorMovableLayer;
			s_clickMove.m_isOnce = true;
			s_clickMove.setVisible(true);
			s_clickMove.m_scene = this.m_scene;
			m_upgradeAcotr.m_layer = m_actorMovableLayer;
			m_upgradeAcotr.m_scene = this.m_scene;
			addDynamicActor(role);

			DWControlsManager.getInstance().removeAllControl();
			DWControlsManager.getInstance().m_drag_control = null;
			UIWindows.getInstance().m_main.open((byte) 0);

			DWGameManager.getInstance().getSendMessage().sendChangeFinished();
			DWGameManager.getInstance().getSendMessage()
					.sendRoleSight(DWGameManager.Screen_Width);
			DWGameManager.getInstance().getSendMessage().sendPrizeMessage();
			if (DWGameManager.getInstance().m_role.m_pathfinding_start) {
				DWGameManager.getInstance().m_role.m_pathfinding_pause = false;
			}

			if (DWControlsManager.getInstance() != null
					&& DWControlsManager.getInstance().m_guides.m_parent != null) {
				DWControlsManager.getInstance().m_guides.m_parent.closeGuide();
			}

			// if (UIWindows.getMain() != null) {
			// UIWindows.getMain().updateSkillSet();
			// }
			// if (UIWindows.getMain() != null) {
			// UIWindows.getMain().updateLv();
			// }
			// if (UIWindows.getMain() != null) {
			// UIWindows.getMain().updateExp();
			// }
			// if (UIWindows.getMain() != null) {
			// UIWindows.getMain().updateMyHead();
			// }
			// if (UIWindows.getMain() != null) {
			// UIWindows.getMain().updateOpenIcon();
			// }
			// if (UIWindows.getMain() != null) {
			// UIWindows.getMain().refreshMapName();
			// }
			// // if (UIWindows.getMain() != null) {
			// // UIWindows.getMain().horn();
			// // }
			if (DWGameManager.getInstance().m_role.m_teamID != 0) {
				DWGameManager
						.getInstance()
						.getSendMessage()
						.sendTeamFristLogin(
								DWGameManager.getInstance().m_role.m_teamID);
			}
		}

		@Override
		public void quit()
		{
			try {
				DWGameManager.getInstance().m_role.stopCasting();
				DWGameManager.getInstance().m_role.stopCastingDescription();
				if (DWGameManager.getInstance().m_role.m_curCombatSkill != null
						&& DWGameManager.getInstance().m_role.m_curCombatSkill
								.isActive()) {
					DWGameManager.getInstance().m_role.m_curCombatSkill
							.deactive();
				}
				DWGameManager.getInstance().m_role.m_curCombatSkill = null;
				removeGameActorByID(DWGameManager.getInstance().m_role.m_gameId);
				ResourceManager.getInstance().removeResource(
						DWGameManager.getInstance().m_resourceDynamic,
						this.m_scene.m_resHead);
				dispose();

				if (DWGameManager.s_change_role) {
					DWGameManager.getInstance().m_resourceDynamic.removeAll();
				}
			}
			catch (Exception e) {
				Tools.debug(e);
			}
		}

		public boolean onTouch(MotionEvent event, PointF point)
		{
			if (DWControlsManager.getInstance() != null)
				return DWControlsManager.getInstance().onTouch(event, point);
			return false;
		}
	}

	/**
	 * 更新天气和音乐
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvWEATHERANDMUSIC(DataInputStream dis) throws IOException
	{
		byte weatherType = dis.readByte(); // 天气类型
		byte musicID = dis.readByte(); // 音乐类型
		DWAudio.getInstance().loadMusic(musicID);
		DWAudio.getInstance().playMusic();
	}

	/**
	 * 同步队伍消息3010
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvTeamMSG(DataInputStream dis) throws IOException
	{
		int memberNum = dis.readInt(); // 队员数量
		Tools.debugPrintln("memberNum:" + memberNum);
		Vector rolelist = DWGameManager.getInstance().m_role.m_roleTeam;
		for (int i = 0; i < memberNum; i++) {
			long gameID = dis.readLong(); // 队员ID
			byte online = dis.readByte();
			int maxHp = 0, hp = 0, x = 0, y = 0;
			if (online == 0) {
				maxHp = dis.readInt();
				hp = dis.readInt();
				x = dis.readInt();
				y = dis.readInt();
			}
			for (int j = 0; j < rolelist.size(); j++) {
				Role role = (Role) rolelist.elementAt(j);
				if (gameID == role.m_gameId) {
					// role.m_online = (dis.readByte() == 0 ? true : false);
					if (online == 0) {
						role.m_hpMax = maxHp;
						role.m_hp = hp;
						role.m_posX = x;
						role.m_posY = y;
					}
				}
			}
		}
		if (UIWindows.getMain() != null) {
			UIWindows.getMain().updateTeam();
		}
	}

	/**
	 * 聊天
	 *
	 * @throws IOException
	 */
	private void recvChatInfos(DataInputStream dis) throws IOException
	{
		Tools.debugPrintln("获得聊天信息 ------------------");
		ChatItem item = ChatItem.readChatInfos(dis);
		DWGameManager.getInstance().m_role.addToChat(item);
	}

	/**
	 * 大喇叭喊话
	 *
	 * @param dis
	 */
	private void recvChatWorld(DataInputStream dis)
	{
		byte state = 0;
		try {
			state = dis.readByte();
		}
		catch (IOException e) {
		}
		if (state == 0) {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_B, "您没有大喇叭，无法发言");
		}
		else {
			if (DWControlsManager.getInstance().contains(
					UIWindows.getInstance().m_tyfon.m_tyfon_frame)) {
				DWControlsManager.getInstance().removeControl(
						UIWindows.getInstance().m_tyfon.m_tyfon_frame);
			}
		}
	}

	private String recvReadString(DataInputStream dis) throws IOException
	{
		return dis.readUTF();
	}

	public void recvInfo(DataInputStream dis) throws IOException
	{
		long id_sender = dis.readLong();
		String name = dis.readUTF();
		byte zhenying = dis.readByte(); // 阵营
		byte vip = dis.readByte(); // vip
		byte type = dis.readByte();
		String info = dis.readUTF();
		String temp = type < 10 ? "0" + type : String.valueOf(type);
		ChatItem item = null;
		if (id_sender == ChatItem.ID_SYSTEM) {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_E, temp + info);
			item = ChatItem.createChatItem(ChatItem.TYPE_XI, id_sender, "",
					"您", info, zhenying, vip);
		}
		else {
			DWGameManager.getInstance().addSystemInfo(
					DWGameManager.SYSTEM_INFO_TYPE_E, temp + name + ":" + info);
			item = ChatItem.createChatItem(ChatItem.TYPE_WORLD, id_sender,
					name, "您", info, zhenying, vip);
		}
		DWGameManager.getInstance().m_role.addToChat(item);
	}

	/**
	 * 开启兑换礼包
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvGiftBagOpen(DataInputStream dis) throws IOException
	{
		UIWindows.getInstance().m_giftBag.open((byte) 0);
	}

	// ////////////////////////////////////////////////////////////////
	// // 提示信息相关(无消息框，仅在屏幕上绘制字符串)
	public int m_curMessageColorWord;
	public int m_curMessageColorShadow;
	public String m_curMessageContent;
	public int m_curMessageFrameCounter;
	public static final int MESSAGE_DURATION = 40;

	/**
	 * 添加提示消息
	 *
	 * @param content
	 * @param color
	 */
	public void addMessage(String content, int colorWord, int colorShadow)
	{
		m_curMessageContent = content;
		m_curMessageColorWord = colorWord;
		m_curMessageColorShadow = colorShadow;
		m_curMessageFrameCounter = MESSAGE_DURATION;

	}

	/**
	 * 显示提示信息
	 *
	 * @param g
	 */
	public void showMessage(DWGraphics g)
	{
		if (m_curMessageFrameCounter > 0) {
			g.setClip(0, 0, DWGameManager.Screen_Width,
					DWGameManager.Screen_Height);
			g.drawShadowString(m_curMessageContent, m_curMessageColorShadow,
					m_curMessageColorWord, DWGameManager.Screen_Width / 2,
					DWGameManager.Screen_Height / 6, DWGraphics.TOP
							| DWGraphics.HCENTER);
		}
	}

	ArrayList<String> m_arrayList = new ArrayList<String>();
	String m_text;
	int m_curMessageFrameCounterB;

	/**
	 * 添加提示消息B
	 *
	 * @param content
	 */
	public void addMessageB(String content, byte type)
	{
		if (type == 0) {

//			for (int i = 0; i < m_arrayList.size(); i++) {
//				if (m_arrayList.get(i).equals(content)) {
//					return;
//				}
//			}
//
//			m_arrayList.add(content);
		}

		//if (m_curMessageFrameCounterB <= 0) {
		m_text = content;
		m_curMessageFrameCounterB = MESSAGE_DURATION;
		//}
	}

	/**
	 * 显示B类型提示框
	 */
	public void showMessageB(DWGraphics g)
	{

		if (m_curMessageFrameCounterB > 0) {

			int w = (int) DWFont.getFont(DWFont.getDefaultFont().getFontSize()).stringWidth(m_text) + 20;
			int h = DWFont.getDefaultFont().getHeight() + 10;

			int y = DWGameManager.Screen_Height - 96 - h;
			g.setColor(0xC0000000);
			g.setClip(0, 0, DWGameManager.Screen_Width,
					DWGameManager.Screen_Height);
			g.fillRoundRect(DWGameManager.Screen_Width - w >> 1, y, w, h, 5, 5);
			g.drawString(m_text, 0xFFFFFFFF, DWGameManager.Screen_Width
					- (w - 20) >> 1, y + 5, 0);

		}
		else {
//			for (int i = 0; i < m_arrayList.size(); i++) {
//				if (m_arrayList.get(i).equals(m_text)) {
//					m_arrayList.remove(i);
//				}
//			}
//			if (m_curMessageFrameCounterB <= 0) {
//				for (int i = 0; i < m_arrayList.size(); i++) {
//					if (m_arrayList.get(i) != null) {
//						addMessageB(m_arrayList.get(i), (byte) 1);
//						return;
//					}
//				}
//			}
		}
	}

	public void updateMessage()
	{
		m_curMessageFrameCounterB--;
		m_curMessageFrameCounter--;
	}

	public CopyOnWriteArrayList<Integer> m_Upgrade_AnimAction; // 添加升级、任务完成动画
	public static Actor m_upgradeAcotr;
	public static int m_upgradeAction_rwup = 1; // 人物升级
	public static int m_upgradeAction_cw = 0; // 宠物升级
	public static int m_upgradeAction_wcrw = 2; // 完成任务

	/**
	 * 添加升级、任务完成动画
	 */
	public void addUpgradeAnimAction(int action)
	{
		if (m_Upgrade_AnimAction == null) {
			m_Upgrade_AnimAction = new CopyOnWriteArrayList<Integer>();
		}
		m_Upgrade_AnimAction.add(action);
	}

	/**
	 * 显示 升级、任务完成动画
	 */
	// public void showUpgradeAnimAction(DWGraphics g)
	// {
	// if (m_Upgrade_AnimAction != null && m_Upgrade_AnimAction.size() > 0) {
	//
	// if (!m_upgradeAcotr.m_actionOverm_Upgrade_AnimAction)
	// return;
	// if (m_upgradeAcotr.m_actionOver) {
	//
	// }
	// if (m_Upgrade_AnimAction.size() > 0) {
	// m_upgradeAcotr.setAction(m_Upgrade_AnimAction.get(0),
	// DWGameManager.getInstance().Screen_Width >> 1,
	// DWGameManager.getInstance().Screen_Height >> 1, true, false);
	// m_upgradeAcotr.draw(g, m_cameraX, m_cameraY);
	// m_upgradeAcotr.nextFrame();
	// m_Upgrade_AnimAction.remove(0);
	// }
	// }
	// }
	/**
	 * 提示升级动画
	 */
	public void drawPromptUpgradeAnim(DWGraphics g)
	{
		if (m_upgradeAcotr != null && !m_upgradeAcotr.m_actionOver) {
			m_upgradeAcotr.draw(g, 0, 0);
			m_upgradeAcotr.nextFrame();
		}
	}

	/**
	 * 提示升级动画
	 */
	public void updatePromptUpgradeAnim()
	{
		if (m_Upgrade_AnimAction != null && m_Upgrade_AnimAction.size() > 0
				&& m_upgradeAcotr.m_actionOver) {
			int actionid = m_Upgrade_AnimAction.remove(0);
			m_upgradeAcotr.m_posX = DWGameManager.getInstance().Screen_Width >> 1;
			m_upgradeAcotr.m_posY = DWGameManager.getInstance().Screen_Height >> 1;
			m_upgradeAcotr.setAction(actionid, false, true);
		}
	}

	/**
	 * 自动采集
	 */
	public void goOnIteract()
	{
		Tools.debugPrintln("=======自动继续采集=======>");
		GameActor m_targetActor = DWGameManager.getInstance().m_role.m_targetActor;
		if (m_targetActor != null) {
			if (m_targetActor.m_type == GameActorConstants.ACTOR_TYPE_GATHERING) {
				DWGameManager.getInstance().m_role.clearPathfinding();
				// DWGameManager.getInstance().m_role.clearFollowTarget();
				DWGameManager.getInstance().m_role.stopCasting();
				DWGameManager.getInstance().m_role.stopCastingDescription();
				DWGameManager.getInstance().getSendMessage()
						.sendNPCList(m_targetActor.m_gameId);
			}
		}
	}

	public void showSkillResultList(DWGraphics g)
	{
		// Object[] sr_show = m_skillResultShow_list.toArray();
		// if (sr_show != null && sr_show.length > 0) {
		// for (int i = 0; i < sr_show.length; i++) {
		// SkillResult sr = (SkillResult) sr_show[i];
		// boolean showing = sr.draw(g);
		// if (!showing) {
		// m_skillResultShow_list.remove(sr);
		// }
		// }
		// }

		try {
			for (SkillResult sr : m_skillResultShow_list) {
				boolean showing = sr.draw(g);
				if (!showing) {
					m_skillResultShow_list.remove(sr);
				}
			}
		}
		catch (Exception e) {
			m_skillResultShow_list.clear();
			Tools.debug(e);
		}
	}

	// //////////////////////////////////////////////////////
	// // cutin相关

	public boolean m_cutin_show = false;
	public int m_cutin_framecounter;
	private Actor m_cutin;
	public static final String URL_CUTIN = "/anim/cutin";
	public static final int CUTIN_FRAME = 25;

	public void startCutin(int vocation, int sex)
	{
		String str_vocation = null, str_sex = null;
		switch (vocation) {
			case GameActorConstants.职业_剑客:
				str_vocation = "_jianke";
				break;
			case GameActorConstants.职业_道士:
				str_vocation = "_fashi";
				break;
			case GameActorConstants.职业_武者:
				str_vocation = "_daoke";
				break;
			default:
				str_vocation = "_daoke";
				break;
		}
		switch (sex) {
			case GameActorConstants.性别_男:
				str_sex = "_nan";
				break;
			case GameActorConstants.性别_女:
				str_sex = "_nv";
				break;
			default:
				str_sex = "_nv";
				break;
		}
		Animation anim = (Animation) UIWindows
				.createAnimation(URL_CUTIN + str_vocation + str_sex
						+ DWSerializableFactory.EXTENSION_ANIM);
		if (anim == null) {
			Tools.debugPrintln("Cutin资源异常：" + URL_CUTIN + str_vocation
					+ str_sex + DWSerializableFactory.EXTENSION_ANIM);
			return;
		}
		m_cutin = new Actor(anim);
		m_cutin.setAction(0, true);
		m_cutin.m_isOnce = true;
		m_cutin.activate();
		m_cutin_show = true;
		m_cutin_framecounter = CUTIN_FRAME;
	}

	public void endCutin()
	{
		m_cutin_show = false;
		m_cutin_framecounter = 0;
		if (m_cutin != null) {
			m_cutin.destroy();
		}
	}

	public void showCutin(DWGraphics g)
	{
		if (!m_cutin_show)
			return;
		g.setClip(0, 0, DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		g.setColor(0xaa000000);
		g.fillRect(0, 0, DWGameManager.Screen_Width,
				DWGameManager.Screen_Height);
		if (m_cutin != null && m_cutin.m_enabled) {
			m_cutin.m_posX = m_cameraX + m_cameraW / 2;
			m_cutin.m_posY = m_cameraY + m_cameraH / 2;
			m_cutin.draw(g, m_cameraX, m_cameraY);
			m_cutin.nextFrame();
		}
		logicCutin();
	}

	public void logicCutin()
	{
		if (!m_cutin_show)
			return;
		if (m_cutin_framecounter > 0) {
			m_cutin_framecounter--;
		}
		else {
			endCutin();
		}
	}

	// // cutin相关
	// ////////////////////////////////////////////////
	byte status;// 状态
	/**
	 * 接收修改密码
	 *
	 * @param dis
	 * @throws IOException
	 */
	public static String m_login_password = "修改密码";

	private void recvChangePassword(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		status = dis.readByte();
		switch (status) {
			case 0:
				DWGameManager.getInstance().showToast("提示: 未知错误!", 1000);
				break;
			case 1:
				m_login_password = dis.readUTF();
				if (DWGameManager.getInstance().getGameState() == DWGameManager.GS_GAME) {
					if (Login.m_ckecked_fag) {
						Login.Read();
						if (Login.m_back_l_ib1
								.equals(UIWindows.getInstance().m_main.m_u_ib1
										.getText())) {
							write_update();
						}
					}
					final DWMessageBox m_mb = new DWMessageBox("提示", "恭喜您,密码修改成功!");
					m_mb.addListener(new DWListener() {
						public void OnDoubleClick()
						{
						}

						public void OnClick()
						{
							if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
								Tools.debugPrintln("确定");
								DWControlsManager.getInstance().removeControl(m_mb);
								DWGameManager
										.getInstance()
										.addSystemInfo(
												DWGameManager.SYSTEM_INFO_TYPE_B,
												"账号："
														+ UIWindows.getInstance().m_main.m_u_ib1
																.getText()
														+ " 新密码："
														+ m_login_password);
								DWControlsManager
										.getInstance()
										.removeControl(
												UIWindows.getInstance().m_main.m_change_frame);
							}
							else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
								Tools.debugPrintln("返回");
								DWControlsManager.getInstance().removeControl(m_mb);
							}
						}
					});
					DWControlsManager.getInstance().addControl(m_mb);
					return;
				}
				break;
			case 2:
				DWGameManager.getInstance().showToast("提示: 账号错误!", 1000);
				break;
			case 3:
				DWGameManager.getInstance().showToast("提示: 密码错误!", 1000);
				break;
		}
	}

	/**
	 * 接收绑定账号
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvAccountBinding(DataInputStream dis) throws IOException
	{
		status = dis.readByte();
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		switch (status) {
			case 0:
				DWGameManager.getInstance().showToast("提示：未知错误!", 1000);
				break;
			case 1:
				if (DWGameManager.getInstance().getGameState() == DWGameManager.GS_GAME) {
					final DWMessageBox mb = new DWMessageBox("提示", "恭喜您,账号绑定成功!");
					mb.addListener(new DWListener() {
						public void OnDoubleClick()
						{
						}

						public void OnClick()
						{
							if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
								Tools.debugPrintln("确定");
								DWControlsManager.getInstance().removeControl(mb);
								DWControlsManager
										.getInstance()
										.removeControl(
												UIWindows.getInstance().m_main.m_bind_frame);
							}
							else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
								Tools.debugPrintln("返回");
								DWControlsManager.getInstance().removeControl(mb);
							}
						}
					});
					DWControlsManager.getInstance().addControl(mb);
					return;
				}
				break;
			case 2:
				DWGameManager.getInstance().showToast("提示：账号错误!", 1000);
				break;
			case 3:
				DWGameManager.getInstance().showToast("提示:密码错误!", 1000);
				break;
			case 4:
				DWGameManager.getInstance().showToast("提示:此账号已经绑定,无需再重复绑定!", 1000);
				break;
		}
	}

	/**
	 * 接收解除绑定
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvAccountUnbind(DataInputStream dis) throws IOException
	{
		status = dis.readByte();
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		switch (status) {
			case 0:
				DWGameManager.getInstance().showToast("提示：未知错误!", 1000);
				break;
			case 1:
				if (DWGameManager.getInstance().getGameState() == DWGameManager.GS_GAME) {
					final DWMessageBox m_mb = new DWMessageBox("提示", "账号成功解除绑定!");
					m_mb.addListener(new DWListener() {
						public void OnDoubleClick()
						{
						}

						public void OnClick()
						{
							if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
								Tools.debugPrintln("确定");
								DWControlsManager.getInstance().removeControl(m_mb);
								DWControlsManager
										.getInstance()
										.removeControl(
												UIWindows.getInstance().m_main.m_unbind_frame);
							}
							else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
								Tools.debugPrintln("返回");
								DWControlsManager.getInstance().removeControl(m_mb);
							}
						}
					});
					DWControlsManager.getInstance().addControl(m_mb);
					return;
				}
				break;
			case 2:
				DWGameManager.getInstance().showToast("提示：账号错误!", 1000);
				break;
			case 3:
				DWGameManager.getInstance().showToast("提示:密码错误!", 1000);
				break;
			case 4:
				DWGameManager.getInstance()
						.showToast("提示:此账号已经解除绑定,不需要重复解除!", 1000);
				break;
		}
	}

	/**
	 * 接收找回密码
	 *
	 * @param dis
	 * @throws IOException
	 */
	private void recvRetrievePassword(DataInputStream dis) throws IOException
	{
		status = dis.readByte();
		DWGameManager.getInstance().getSendMessage()
				.unlockNetwork(GameMessage.锁_默认);
		switch (status) {
			case 0:
				DWGameManager.getInstance().showToast("提示:未知错误!", 1000);
				break;
			case 1:
				if (DWGameManager.getInstance().getGameState() == DWGameManager.GS_GAME) {
					final DWMessageBox m_mb = new DWMessageBox("提示", "成功找回密码!");
					m_mb.addListener(new DWListener() {
						public void OnDoubleClick()
						{
						}

						public void OnClick()
						{
							if (m_mb.getResult() == DWMessageBox.SOFTKEY_OK) {
								Tools.debugPrintln("确定");
								DWGameManager.getInstance().addSystemInfo(
										DWGameManager.SYSTEM_INFO_TYPE_B,
										"手机短信找回密码尚未开放，请您去邮箱找回密码。");
								DWControlsManager.getInstance().removeControl(m_mb);
								DWControlsManager.getInstance().removeControl(
										UIWindows.getInstance().m_main.m_ret_frame);
							}
							else if (m_mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
								Tools.debugPrintln("返回");
								DWControlsManager.getInstance().removeControl(m_mb);
							}
						}
					});
					DWControlsManager.getInstance().addControl(m_mb);
					return;
				}
				break;
			case 5:
				DWGameManager.getInstance().showToast("提示: 与绑定的手机号码不一致!", 1000);
				break;
			case 6:
				DWGameManager.getInstance().showToast("提示: 与绑定的邮箱不一致!", 1000);
				break;
		}
	}

	private void write_update()
	{
		if (UIWindows.getInstance().m_main.m_u_ib1.getText() != null
				&& UIWindows.getInstance().m_main.m_u_ib3.getText() != null) {
			Login.m_sp1
					.edit()
					.putString("m_l_ib1",
							UIWindows.getInstance().m_main.m_u_ib1.getText())
					.commit();
			Login.m_sp2
					.edit()
					.putString("m_l_ib2",
							UIWindows.getInstance().m_main.m_u_ib3.getText())
					.commit();
			Login.m_sp3.edit().putBoolean("m_l_cb", true).commit();
		}
	}

}
